git grep's --cached option appears to search in changes that are UNstaged (which looks like a bug, as it's not what its docs say, and it's not how git diff treats its --cached option).
Doing git grep --cached foo gets:
somefile.txt: foo: true
To stage these, use cut to extract just the filenames: git grep --cached foo | cut -d : -f 1:
somefile.txt
and then xargs to stage that list: git grep --cached foo | cut -d : -f 1 | xargs git add.
git grep's--cachedoption appears to search in changes that are UNstaged (which looks like a bug, as it's not what its docs say, and it's not howgit difftreats its--cachedoption).Doing
git grep --cached foogets:To stage these, use
cutto extract just the filenames:git grep --cached foo | cut -d : -f 1:and then xargs to stage that list:
git grep --cached foo | cut -d : -f 1 | xargs git add.