简体   繁体   English

Git 解决一些后的冲突

[英]Git conflicts after resolving some

I have problem我有问题

I have trouble getting my pull request of long living branch to get merged into the master, because I have conflicts that aren't solved even if I try to solve them.我很难将长期存在的分支的拉取请求合并到主分支中,因为即使我尝试解决它们也无法解决冲突。

So I see that GitHub tells me that I have conflicts so I cannot merge my feature branch my-feature-branch into the master.所以我看到 GitHub 告诉我有冲突,所以我无法将我的功能分支my-feature-branch合并到主分支中。 I create a new branch solve-conflicts-branch from the my-freature-branch .我从my-freature-branch创建了一个新的分支solve-conflicts-branch -branch 。 I merge master into the solve-conflicts-branch.我将 master 合并到 solve-conflicts-branch 中。 Now I have conflicts in the solve-conflicts-branch and I solve those by using "Theirs" and some of the conflicts using "Mine".现在,我在solve-conflicts-branch中遇到了冲突,我使用“他们的”来解决这些冲突,使用“我的”来解决一些冲突。 I commit the changes and create PR to merge these changes to the my-feature-branch .我提交更改并创建 PR 以将这些更改合并到my-feature-branch So PR goes through and I merge.所以 PR 通过了,我合并了。

What I expect to see is that the first PR gets updated and the conflicts are solved but this is not the case.我希望看到的是第一个 PR 得到更新并且冲突得到解决,但事实并非如此。 The same conflicts that I resolved in the solve-conflicts-branch are still there.我在solve-conflicts-branch中解决的相同冲突仍然存在。

When you squash, you are tricking git (in a very nasty for you way) into thinking that the merge did not take place.当你压扁时,你在欺骗 git(以一种对你来说非常讨厌的方式)认为合并没有发生。 Let me explain so you can see what the problem is when you squash.让我解释一下,这样您就可以在压扁时看到问题所在。 Suppose you have this:假设你有这个:

*   Something on a branch (some-branch)
| * first tip of master (master)
|/
* second commit
* first commit

Suppose that you run a first merge.假设您运行第一次合并。 When you merge, git will, roughly, consider the differences introduced by both branches since their last common ancestor.... so, if you merged master into some-branch to pick up the latest from other developers, git would have to consider this tree, right?当您合并时,git 将粗略地考虑两个分支自其最后一个共同祖先以来引入的差异....因此,如果您将master合并到some-branch以从其他开发人员那里获取最新版本,git 将不得不考虑这一点树,对吧?

*   Something on a branch (some-branch)
| * first tip of master (master)
|/
* second commit

When you finish the merge, you might get something like this (assume we solved some conflicts in the merge):当你完成合并时,你可能会得到这样的东西(假设我们解决了合并中的一些冲突):

* Merging changes from master (some-branch)
|\
* | Something on a branch
| * first tip of master (master)
|/
* second commit
* first commit

That all looks beautiful to me.... now, time goes by a little bit and now we have this:这一切对我来说都很美……现在,时间流逝了一点,现在我们有了这个:

* A new commit in feature branch (some-branch)
| * A new commit in master (master)
* | Merging changes from master
|\|
* | Something on a branch
| * first tip of master
|/
* second commit
* first commit

If you tried to merge this time, again, git would have to look for the latest common ancestor and see what changed on each branch from there so, it would have to consider this (look at the last common ancestor):如果你这次尝试合并,git 将不得不寻找最新的共同祖先并查看每个分支上发生了什么变化,因此,它必须考虑这一点(查看最后一个共同祖先):

* A new commit in feature branch (some-branch)
| * A new commit in master (master)
* | Merging changes from master
 \|
  * First tip of master

Now, if in the last commit of each branch there is no messing up with the code that was already conflicting in the first merge, you would not get a complain from git involving that piece of code as it would not be involved in changes coming from any of the two branches past first tip of master .现在,如果在每个分支的最后一次提交中没有弄乱在第一次合并中已经发生冲突的代码,您将不会收到来自 git 的涉及该代码段的投诉,因为它不会涉及来自的更改过去first tip of master的两个分支中的任何一个。

Now, consider what the first merge would look like after the first merge if you squash:现在,考虑一下如果压缩,第一次合并后第一次合并会是什么样子:

* Merging changes from master (some-branch)
*   Something on a branch
| * first tip of master (master)
|/
* second commit
* first commit

Now, let's add the 2 commits at the tip of each branch, like we did before:现在,让我们在每个分支的顶端添加 2 个提交,就像我们之前所做的那样:

* a new commit in feature branch (some-branch)
* Merging changes from master
*   Something on a branch
| * A new commit in master (master)
| * first tip of master
|/
* second commit
* first commit

If you tried merging now, what tree would git have to consider to merge?如果你现在尝试合并,git 必须考虑合并什么树? It would have to again consider changes coming since second commit , just like last time and , given that there were conflicts before, it's more than likely that the 2 branches will still conflict on the same sections of code because, to git, you have different changes coming from the 2 branches since second commit .它将不得不再次考虑自second commit以来发生的变化,就像上次一样,鉴于之前存在冲突,这两个分支很可能仍然会在相同的代码部分发生冲突,因为对于 git,你有不同的自second commit以来来自 2 个分支的更改。 So, yes, you solved conflicts before, but given that you did not really merge, git does not know about it when you are trying to merge this time.所以,是的,你之前解决了冲突,但考虑到你并没有真正合并,git 在你这次尝试合并时并不知道。

I hope that helps explain why it happens.我希望这有助于解释为什么会这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM