如何搜索(git grep)在特定的提交和文件类型的变化?



我想搜索所有更改在一个特定的提交中。请注意,我只想搜索更改的部分,而不是整个更改的文件。

这是我尝试的:

$ git grep -A5 -E -e 'search_term(.*?,'  <commit_hash>

我似乎不能把它限制在一次提交中。返回的结果还包括在本次提交中未更改的文件的搜索结果。

如何限制搜索到特定的文件名和类型?我可以限制扩展,但不能使用如下所示的模式:

$ git grep -A5 -E -e 'search_term(.*?,'  <commit_hash> -- '*.ts
... works
$ git grep -A5 -E -e 'search_term(.*?,'  <commit_hash> -- 'file_prefix.*.ts
... does not work!

查看

  • git log -G <pattern> #及其各种选项
  • git log -S #及其各种选择
  • git show <hash>
  • git log -p ... | grep

有很多不同的方法可以做到这一点。使用上面的命令和git help <command>,您应该能够找到您正在寻找的具体内容。

最新更新