我向 repo 协议(protocol)添加了一些代码行并提交了它。然后提交次数之后,这些行已被删除。
我有添加行时的提交散列和删除它们的后续提交的散列。我怎样才能找到它们被删除的确切提交?
最佳答案
您可以使用 -S
或 -G
git log
的选项.它们之间的区别在于 -S
采用固定字符串(代表您要匹配的代码行),而 -G
做同样的事情,但采用正则表达式:
git log --oneline -S 'fixed string'
git log --oneline -G '^foobar$'
-S
和 -G
选项将返回首先引入或删除字符串/正则表达式模式的提交。您甚至可以添加 --patch
或 -p
如果您想查看提交匹配项的差异,请选择此选项。
文档
来自official Linux Kernel git log
documentation :
-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.-G <regex>
Look for differences whose added or removed line matches the given
<regex>
.
关于git - 如何找到删除了某些代码的 Git 提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24193759/