git grep - 但只限于索引中的新文件或修改过的文件 [英] git grep--but restricted to new or modified files in the index
问题描述
是否有可能获得 git grep
来仅搜索索引/缓存中的新文件或修改过的文件?
$ b
(这个用例是用于查找调试代码的预提交钩子,例如 console.log
在预期的提交中,但是我并没有被现有代码中的 console.log
所困扰,最好也不能匹配 console.log
已被删除,但我可以接受这些匹配!)
原来这样做并不是通过 git grep
,而是通过完全不同的命令,这也恰好能够搜索: git diff-index
。 (另一个简单性和正交性的胜利......)
我想要的可以通过以下方式实现:
$ git diff-index -U --cached -G< regexp> HEAD
Is it possible to get git grep
to search only new or modified files in the index/cache?
(The use-case for this is to use in a pre-commit hook that looks for "debug" code such as console.log
in the prospective commit. But I'm not bothered by console.log
in "existing" code. Preferably this would also fail to match instances of console.log
that are removed, but I can live with those matching!)
It turns out the way to do this is not via git grep
, but by a completely different command, that also happens to be able to search: git diff-index
. (Another triumph for simplicity and orthogonality...)
What I wanted can be achieved via:
$ git diff-index -U --cached -G <regexp> HEAD
这篇关于git grep - 但只限于索引中的新文件或修改过的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!