git - 如何在 git 历史记录中搜索消失的行?

标签 git

我需要在 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/

相关文章:

SCSS 。将更改从一个文件 merge 到同一分支中的另一个文件

windows - PowerShell-git checkout -B没有重置或替代方法?

Powershell 中的 Git 说 'Could not find ssh-agent'

git - 推送到远程仓库时如何使用不同的分支名称

git - 移动 .git 目录

git - 如何/在何处备份推送到服务器之间 DVCS 的本地 checkout ?

来自远程主服务器的 Git Rebase

git - git 可以忽略与模式匹配的特定行吗?

javascript - 我可以使用 NodeGit 从特定提交中获取加法和减法吗?

git svn 模糊参数 'HEAD'