0

我的 git repo 中有一个文件被更改了很多次。我想知道此文件中存在特定文本的修订版本。

是否有 git 命令来获取此信息?

就像是:

git find "specific_text" -- /frequently/modified/file

这将输出提交列表。

4

2 回答 2

2

git grep <pattern>将搜索当前提交

如果要搜索git 的所有历史记录,请使用镐选项之一:

git log -G "specific_text" -- frequently/modified/file
# or :
git log -S "specific_text" -- frequently/modified/file

文档中解释了两者之间的区别:

  • -G将列出specific_text出现在差异中的所有提交,
  • -S将仅列出specific_text更改计数的提交,例如:此文本出现的提交,它被删除的提交,但不会列出只是移动它而不添加或删除实例的提交。

-p如果您想查看差异本身,也可以添加:

git log -p -S "specific_text" -- frequently/modified/file
于 2020-10-15T13:32:06.350 回答
1

你可以做

git log -G 'specific text' --  /frequently/modified/file
于 2020-10-15T13:30:28.590 回答