git revert:在实际还原之前是否可以识别可能存在冲突的提交?

Rom*_*kyi 5 git git-revert

有没有办法识别特定提交的"附带"提交(编辑相同行并将导致冲突的提交)?

一个非常简单的例子

$ git init
$ echo test > test
$ git add test
$ git commit -m "First commit"
$ echo test1 > test
$ git commit -am "Second commit"
$ git l
* 95a29dd Second commit
* 30a68e6 First commit
$ type test
test1
Run Code Online (Sandbox Code Playgroud)

假设在这一点上无论出于何种原因我想要恢复30a68e6.

$ git revert 30a68e6
error: could not revert 30a68e6... First commit
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
Run Code Online (Sandbox Code Playgroud)

当然,这会导致冲突,因为95a29dd编辑了相同的行.

是否有可能提前发现恢复30a68e6会导致冲突,如果是,那么提交(即95a29dd)?

为了给出一些上下文,我需要这个,因为我需要一些提交才能自动恢复.在这种情况下,如果我知道30a68e6应该还原,我希望能够识别"抵押"提交,应该首先恢复以避免任何冲突(如30a68e6).我知道只是恢复一切30a68e6..HEAD,会有效,但我想避免恢复不会与之冲突的提交30a68e6.

oyv*_*ind 0

git revert应该很容易撤消。检查恢复的返回代码,git revert --abort如果失败(返回代码 1)或git reset --hard HEAD~1成功(返回代码 0)并且您不想保留它,则运行。

您也许可以git bisect根据您的需要将其与历史记录结合起来进行搜索。