这是我所拥有的:
$ ls
file
$ cat file
change 1
change 2
change 3
$ git log --oneline
8979b76 Add change 3 to file
ff1aead Add change 2 to file
53559fe Add change 1 to fileQ1 :这就是我所做的和我得到的:
$ git revert 53559fe
error: could not revert 53559fe... Add change 1 to file
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'
$ cat file
change 1
change 2
change 3为什么会这样呢?
Q2:然后我做到了:
$ git revert --abort
$ git revert ff1aead
error: could not revert ff1aead... Add change 2 to file
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'
$ cat file
change 1
<<<<<<< HEAD
change 2
change 3
=======
>>>>>>> parent of ff1aead... Add change 2 to file为什么我得到一个错误?
如何解释文件中的标记?
发布于 2014-12-12 18:37:32
有很多关于标记的信息。如果你只是想合并,看看Fix merge conflicts in Git?。
我假设'change 1‘创建了有问题的文件。如果是这种情况,第一次恢复会失败,因为在更改之前该文件不存在,但现在它存在。您想要的是介于两者之间的某个位置:您可能需要一个文件
change 2
change 3这不能从那里自动计算出来。没有任何标记的原因是,这种冲突不适用于文件的内容,而适用于树。git mergetool非常清楚地说明了这一点;它会询问您是要保留文件还是要删除文件。在这种情况下,您必须保留它并删除第一行。
我猜第二个冲突的出现是因为没有足够的上下文来可靠地自动合并。如果你打开一个3-way-merge工具,你会看到类似这样的东西:
LOCAL | RESULT | REMOTE
change 1 | | change 1
change 2 | |
change 3 | |您必须基于本地和远程中的信息在中间构建结果,这两个信息分别引用您的当前状态和引入change 2之前的状态。
当然,你想要的是
change 1
change 3但是,从这里提供的有限上下文来看,这一点并不明显,不是吗?
https://stackoverflow.com/questions/27437435
复制相似问题