10

It seems git grep doesn't have any option to search only in working directory modified files prior to indexing those files. is there any native git command for this purpose or should I use a combo git/linux commands?

2 Answers 2

14

by using linux grep and git ls-files:

$ grep -s "search pattern" $(git ls-files -m)

note 1: grep's -s option is provided for Suppress error messages about nonexistent or unreadable files because git ls-files -m lists deleted files too which causes grep give "No such file or directory" error when encounters a nonexistent file.

note 2: git ls-files' -m option is for listing only modified files(which also lists removed files too!)

2
0

git grep is modelled on plain grep, perhaps you should just use that.

3
  • 1
    I prefer to use git build-in grep because of performance boost git-grep gives over grep, but if you know commands to get list of modified files and pass it to linux's grep I take that as an answer.
    – sepehr
    Mar 23, 2013 at 23:24
  • Look at git ls-files --modified and such
    – vonbrand
    Mar 24, 2013 at 0:38
  • 1
    it seems you didn't see my answer which use your suggested "git ls-files" command.
    – sepehr
    Mar 24, 2013 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.