How to grep search in modified files of working directory which are not yet been staged(indexed)?

前端 未结 2 1286
天命终不由人
天命终不由人 2020-12-31 16:47

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

相关标签:
2条回答
  • 2020-12-31 17:30

    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!)

    0 讨论(0)
  • 2020-12-31 17:46

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

    0 讨论(0)
提交回复
热议问题