How to git add list of files from git diff
git add --all
and
git add --all <pathspec>
are different.
So,
git diff --name-only | grep '/cache/' | xargs git add --all
is what you want. Additionally, git add
can take multiple arguments on the command line, so what you want can be done with
git add --all $(git diff --name-only | grep '/cache/' )
Instead of using grep use the -G
option of the git diff
command:
git add --all $(git diff -G 'cache' --name-only)