git grep by file extensions

拈花ヽ惹草 提交于 2019-12-03 02:59:41

问题


I know that, if I wanted to grep for a pattern only on files with certain extensions, I could do this:

// 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 here that excluding certain file types is not possible.


回答1:


Yes, for example:

git grep res -- '*.js'



回答2:


Try doing this :

find . -type f -iname '*.js' -exec grep -i 'pattern' {} +


来源:https://stackoverflow.com/questions/13867705/git-grep-by-file-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!