git grep 按文件扩展名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13867705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git grep by file extensions
提问by Vinay
I know that, if I wanted to grep for a pattern only on files with certain extensions, I could do this:
我知道,如果我只想在具有某些扩展名的文件上 grep 模式,我可以这样做:
// searches recursively and matches case insensitively in only javascript files
// for "res" from the current directory
grep -iIr --include=*.js res ./
I've been trying to search for a way to do this via git grep as well (to take advantage of git grep's speed from the indexes it stores with its tree), but to no avail. I saw herethat excluding certain file types is not possible.
我也一直在尝试通过 git grep 寻找一种方法来做到这一点(利用 git grep 与树一起存储的索引的速度),但无济于事。我在这里看到排除某些文件类型是不可能的。
回答by CB Bailey
Yes, for example:
是的,例如:
git grep res -- '*.js'
回答by Gilles Quenot
Try doing this :
尝试这样做:
find . -type f -iname '*.js' -exec grep -i 'pattern' {} +