如何在我的整个 git 存储库的提交历史记录中搜索字符串更改?

How can I search my ENTIRE git repo's commit history for a string change?

我有一个website/repo。

我网站的一部分说:

"Powered by https://myotherwebsite.com/'"

在某些时候,我在网站上工作的一些巨魔将其切换为:

"Powered by https://theirwebsite.com"

如何在整个回购历史中搜索到进行此更改的提交。

多年来有很多commits/branches。

如果您可以忽略死分支并假设所有相关代码都可以从您最新的主版本访问,我建议您使用 git 日志的 -S 选项:

git log -S "theirwebsite"

如果您的实际需求比您在此处描述的更复杂或变得更复杂,请查看 doc, and maybe consider using regexp 搜索。


更好:使用 --all 可以搜索整个存储库(感谢 j6t 的技巧!)

git log --all -S "theirwebsite"

(并且,如 vfalcao 所述,请考虑在此处使用 --name-only 选项列出发生此更改的文件。)