我需要在 git 存储库中搜索特定文件的历史记录,以找到已消失的行。提交消息将没有任何相关文本可供搜索。我使用什么命令?
更多细节:这是我的待办事项列表的历史,来 self 们的非恒星任务跟踪软件。我已经保存它两年了,因为软件中没有为我保留足够的信息。不幸的是,我的提交消息通常只有任务 ID,我需要做的是按主题而不是按编号查找已关闭的任务。是的,真正的解决方案是更好的任务跟踪软件,但这完全不在我的掌控之中。
最佳答案
这是镐的工作!
来自 git-log 联机帮助页:
-S<string>
Look for differences that introduce or remove an instance of
<string>
. Note that this is different than the string simply appearing in diff output; see the pickaxe entry in gitdiffcore(7) for more details.
您当然可以使用更多选项来缩小范围,例如:
git log -Sfoobar --since=2008.1.1 --until=2009.1.1 -- path_containing_change
还有:
-G<regex>
Look for differences whose patch text contains added/removed lines that match . To illustrate the difference between -S --pickaxe-regex and -G, consider a commit with the following diff in the same file:
+ return frotz(nitfol, two->ptr, 1, 0);
...
- hit = frotz(nitfol, mf2.ptr, 1, 0);
While
git log -G"frotz\(nitfol"
will show this commit,git log -S"frotz\(nitfol" --pickaxe-regex
will not (because the number of occurrences of that string did not change).
关于git - 如何在 git 历史记录中搜索消失的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2700140/