gpt4 book ai didi

git - 如何找到删除了某些代码的 Git 提交?

转载 作者:太空狗 更新时间:2023-10-29 13:35:55 24 4
gpt4 key购买 nike

我向 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com