我想知道发生了什么。我创建了一个HTML文件,并在其中添加了一些行
this is first line
this is second line
this is third line
this is fourth line
并且在每一行之后提交,例如分别提交a,commit b,commit c,commit d。
现在我执行了一个恢复提交c,但它抛出一个错误:
could not revert 82b69e5... c
hint: after resolving the conflicts, mark the corrected paths <br>
hint: with 'git add <paths>' or 'git rm <paths>' <br>
hint: and commit the result with 'git commit'<br>
我想知道git-revert是如何工作的。我知道类似的东西“撤消提交并添加新提交”,但不知道成功使用它。
它为你想要恢复的提交创建一个反转补丁,所以在你的情况下,提交c
看起来像:
this is first line
this is second line
+this is third line
# End of file
然后,从d
运行git revert c
,所以它尝试创建以下内容并将其应用于您的树:
this is first line
this is second line
-this is third line
# End of file
但是,您的文件如下所示:
this is first line
this is second line
this is third line
this is fourth line
# End of file
因此创建的补丁不适用(文件结束与第四行冲突)。所以,当Git告诉你:
could not revert 82b69e5... c
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'
这意味着“我试着做你所要求的但是我遇到了一个我无法解决的案例”,所以你需要:
git revert --quit
取消还原最有可能的是,您的解决方案是:
this is first line
this is second line
this is fourth line
git revert命令可以被视为'undo'类型命令,但是,它不是传统的撤销操作。
从本质上讲,它撤消了在指定提交中完成的所有操作,然后在该过程中创建了一个新提交。您可以查看this以获取更多信息。
关于您的问题,您将遇到合并冲突。要解决这些冲突,您可以使用git mergetools(例如Meld)。