成功合并后,Github仍显示分支之间的差异 [英] Github still shows differences between branches after sucessfull merge

查看:199
本文介绍了成功合并后,Github仍显示分支之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我将一个巨大的请求请求(140次提交)从功能分支合并到了主服务器:

Recently I merged a huge pull request (140 commits) from the feature branch to master:

我可以在master分支的github overiew中看到合并:

I can see the merge in the github overiew on the master branch:

但是,当我切换到功能分支时,我可以看到该功能提前141次提交(今天我对功能进行了另一次提交),而在master之后进行了1次提交:

However, when I switch to the feature branch, I can see that feature is 141 commits ahead (today i did another commit on feature) and 1 commit behind master:

现在的主要问题是,我无法将我今天在功能上所做的更改合并到母版中:

And now the main problem is, I cannot merge the change I did today on feature to master:

因为github似乎想再次提交已经合并的140个旧提交(在解决了一些痛苦的冲突之后)

Because github seems to want to commit again the 140 old commits which were already merged (after some painfull conflict resolving)

我该如何再次同步母版和要素,因此它们实际上是什么:它们之间的区别是从今天开始的要素提交.

How can I sync master and feature again, so they are what they actually are: The difference between them is ONLY the commit on feature from today.

推荐答案

您似乎正在使用两个长期运行的分支并正在使用壁球合并.这有点问题,这就是原因.

It looks like you're using two long-running branches and using a squash merge. That's a bit of a problem, and here's why.

当Git执行合并时,它会精确地考虑三个点:您要合并的两个头,以及第三个点,称为 merge base ,通常是它们的共同祖先.合并的结果是合并基础与每个头部之间的变化之和.

When Git performs a merge, it considers exactly three points: the two heads you're merging, and a third point, called the merge base, which is usually their common ancestor. The result of the merge is the sum of the changes between the merge base and each head.

如果使用正常的合并提交合并两个分支,那么您将创建一个新的公共祖先,因此以后的合并将从该基础开始.您不必担心已经合并的东西带来的冲突,因为Git甚至都不会考虑它们.

If you merge two branches with a normal merge commit, then you create a new common ancestor, so future merges start at that base. You don't have to worry about conflicts from things you've already merged because Git doesn't even consider them.

当您通过壁球合并合并两个分支时,您会在一个分支上创建一个提交,其中包含来自另一个分支的所有更改,但是您没有创建新的公共祖先.结果,当您尝试再次合并时,Git会考虑双方的所有更改,最终会导致很多冲突.如果您一直压扁合并两个分支,这只会变得更糟.

When you merge two branches with a squash merge, you create a single commit on one branch that includes all of the changes from the other, but you don't create a new common ancestor. As a result, Git looks at all the changes on both sides when you try to merge again and you can end up with a lot of conflicts. This only gets worse if you keep squash merging the two branches.

因此,除非您真的想一直解决很多冲突,否则您真的必须使用普通的合并提交来集成两个长期运行的分支.壁球合并在这里不起作用.

As a result, you really must use a normal merge commit to integrate two long-running branches unless you really want to resolve lots of conflicts all the time. Squash merges won't work here.

如果feature不需要长时间运行,则只需从master重新创建即可. Git擅长创建要素分支,一旦合并它们就可以丢弃它们.这是解决此问题的最简单方法.由于您需要包含一个提交,因此只需按照与概述的eftshift0相似的步骤进行操作即可:

If feature doesn't need to be long-running, then simply recreate it from master. Git is great at creating feature branches that you can then throw away once they're merged. That's the simplest way to solve this problem. Since you have a commit on it that needs to be included, then just follow the steps similar to those eftshift0 outlined:

$ git checkout feature
$ git rebase --onto master HEAD^
# optionally:
$ git push origin +feature

否则,这是解决此问题的最简单方法.在壁球合并之前对master进行提交,并将其命名为A.在合并的feature上进行提交,并将其命名为B.

Otherwise, here's the easiest way to solve this problem. Take the commit on master immediately before your squash merge and call it A. Take the commit on feature that you merged and call it B.

$ git checkout -b temp A
$ git merge B
$ git checkout master
$ git merge temp

这将创建一个名为temp的分支,该分支看起来像壁球合并,但具有真正的合并提交,然后将其合并到master中.合并是不可操作的,因为双方都是完全相同的,因此您不必解决任何冲突.但是,双方现在共享了一个新的共同祖先,将来的合并可以以此为基础,从而解决了这个问题.然后,在集成两个分支时可以使用普通的合并提交.

This creates a branch called temp which looks exactly like the squash merge, but with a real merge commit, and then merges it into master. This merges is a no-op because both sides are completely identical, so you don't have to resolve any conflicts. However, both sides now share a new common ancestor on which future merges can be based, which solves the problem. You can then use normal merge commits when integrating the two branches.

这篇关于成功合并后,Github仍显示分支之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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