【发布时间】:2021-01-15 18:18:27
【问题描述】:
我想搜索特定提交中的所有更改。请注意,我只想搜索更改,而不是整个更改的文件。
这是我尝试过的:
$ 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 diff thatcommit~ thatcommit -- your path patterns here. -
@jthill 我也想搜索上下文,即搜索中包含任何更改之前的 N 行和之后的 M 行。如何扩展
git diff输出中显示的“上下文”数量?