在GIT中查找具有特定单词/行的最新提交

时间:2013-04-24 23:09:11

标签: git

如果我有一个包含最新提交的文件,请执行以下操作:

class A {
    String name = "Mary";
}

在特定提交中,String name = "Mary";已从String name = "Bob"更改。问题是,这一行已经被修改了几次(一次是"John",另一次是"Adam")所以git blame没用。使用Git,最简单的方法是找出除了挖掘日志之外的最后一次提交行字符串名称=“Bob”的内容。

1 个答案:

答案 0 :(得分:4)

这是我的 go to command

git log -p -S <search term>

更多信息

-p 
Generate patch (see section on generating patches). 
-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.