Git恢复导致合并冲突 [英] Git revert causes merge conflict

查看:118
本文介绍了Git恢复导致合并冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个虚拟txt文件,并在每次提交中输入了新行 例如:

I created a dummy txt file and entered a new line in every commit such as:

//dummy.txt
first commit
second commit
third commit

现在我想通过还原第二个提交来摆脱第二行.但是,在这个简单的实验中,我收到合并冲突.有人可以解释为什么吗?

now I want to get rid of the second line by reverting the second commit. However I receive merge conflicts in this simple experiment. Could somebody explain why?

推荐答案

您的示例实际上并不像您想象的那么琐碎,因为您所做的更改都是连续的.主要问题是third commit引入的差异实际上取决于second commit中所做的更改. Git存储了每个提交的完整树,但是仍然需要能够将一个提交表示为与前一次提交相比的差异(不知道这对您是否有意义).

Your example is actually not as trivial as you may think, because your changes are all on consecutive lines. The main problem is that the diff introduced by third commit actually depends on changes done in second commit. Git stores the full tree of each commit, but still needs to be able to express a commit as a diff in terms of the previous commit (don't know if that makes sense to you).

如果您尝试相同的操作,但是通过执行3次提交来修改同一文件的不同部分,则第二次提交的还原不会失败.由于默认的内容差异为3,因此,如果您所做的编辑彼此之间相距3行以上,它不会失败.

If you try the same operations but by doing 3 commits modifying different parts of the same file, the revert of the second commit will not fail. Since the default context diff is 3, it should not fail if your edits are further than 3 lines apart from each other.

这篇关于Git恢复导致合并冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆