如何grep搜索尚未上演(索引)的工作目录的修改文件? [英] How to grep search in modified files of working directory which are not yet been staged(indexed)?
问题描述
似乎 git grep
没有任何选项可在索引这些文件之前仅在工作目录修改的文件中进行搜索。是否有任何原生git命令为此目的,或者我应该使用组合git / linux命令?
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?
推荐答案
通过使用linux grep
和 git ls-files
:
by using linux grep
and git ls-files
:
$ grep -s "search pattern" $(git ls-files -m)
注1:为提供了grep的
-s
选项,用于抑制关于不存在或不可读文件的错误消息$ c $因为 git ls-files -m
列出了删除的文件,导致 grep
给出遇到不存在的文件时,没有这样的文件或目录
错误。
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.
注意2:git ls-files' - m
选项仅用于列出修改
文件(其中也列出了已删除的文件!)
note 2: git ls-files' -m
option is for listing only modified
files(which also lists removed files too!)
这篇关于如何grep搜索尚未上演(索引)的工作目录的修改文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!