git grep by文件扩展名

Vin*_*nay 81 git grep file-extension

我知道,如果我只想对具有特定扩展名的文件进行格式化,我可以这样做:

// searches recursively and matches case insensitively in only javascript files
// for "res" from the current directory
grep -iIr --include=*.js res ./
Run Code Online (Sandbox Code Playgroud)

我一直试图通过git grep搜索一种方法(利用git grep从它存储的索引中获得的速度),但无济于事.我在这里看到不能排除某些文件类型.

CB *_*ley 133

是的,例如:

git grep res -- '*.js'
Run Code Online (Sandbox Code Playgroud)

  • aehlke `--` 是许多 git 命令中的常见分隔符,用于将参数与要操作的一组文件分隔开。 (4认同)
  • 一个小小的修改 - 如果你不在你的存储库的根目录,`git grep res - '/*.js'`可能会更好...... (3认同)
  • 只是额外的信息:如果你想指定一组文件扩展名,你可以使用`git grep res - *.js*.cs`这在另一个[问题]中有所涉及(http://stackoverflow.com/questions/21599474 /如何到混帐的grep只-A-设置的文件,一些推广) (3认同)
  • “-”完成什么工作? (2认同)
  • 重要的是不要忘记'*.js' 周围的单引号。如果他们不在那里,它就行不通。(shell 会在它到达 git 之前拦截它)。 (2认同)