[小技巧] 如何在 git 里查找哪一个 commit 删除了代码的一行

时间:2021-08-10 04:07:00

本文转载至:http://*.com/questions/4404444/how-do-i-blame-a-deleted-line

If you know the contents of the line, this is an ideal use case for:

git log -S <string> path/to/file

which shows you commits which introduce or remove an instance of that string. There's also the -G<regex> which does the same thing with regular expressions! See man git-log and search for the -G and -S options, or pickaxe (the friendly name for these features) for more information.

The -S option is actually mentioned in the header of the git-blame manpage too, in the description section, where it gives an example using git log -S....


说明:使用git log 的 -S 选项来指定 commit 里包括的字符串。