问题描述
这是一种使用文本搜索来搜索已更改文件(删除或添加了代码)的提交的方法吗?
例如: 我已经连接到我的团队资源库,现在我可以看到提交的历史了。我想搜索一个提交,其中“ isGlossaryTermUsed”行已更改(添加或删除)。我知道我可以使用“搜索工具”进行搜索,但前提是代码中只有这样的行,并且以此方式,我无法看到提交者添加或删除的更改。
我的英语不好,我希望我正确地提出了这个问题。预先感谢。
解决方法
git log
具有-G <pattern>
选项(docs here):
它将仅列出 diff 包含上述模式的提交。
您可以将其与其他git log
选项结合使用:
# will list commits along with the files they modified :
git log --name-only/--name-status
# will list a file *only* if its diff matches <pattern>
git log --name-only/--name-status -G <pattern>
# will list commits along with the diff (the 'patch') of the commit :
git log -p
# will show the diff of file where <pattern> appears
git log -p -G <pattern>
还有-S <pattern>
选项(docs right next to -G),它增加了一个额外的变化:
仅当<pattern>
出现的次数更改。
第二个选项将保留模式出现或消失的提交,并忽略仅移动模式的提交。
在GUI的某处可能有一个为git提供此选项的字段(我对Eclipse git不熟悉),寻找一个字段,该字段显示为-S
,-G
或{{1 }}。