Git分支在rebase之后分歧 [英] Git branch diverged after rebase

查看:275
本文介绍了Git分支在rebase之后分歧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Git建议我的分行和远程分行,并且:



,分别有109和73个不同的提交

会推动我的分支解决这个问题 - 也就是说,解决方案

当你为一个分支重新绑定时,你必须重写提交到分支上的提交之上的任何提交,你正在重塑。这是因为提交的其中一个属性是其父项(或父项)。当你重新绑定的时候,你改变了你的分支上最旧的本地提交的父对象,并且因此改变了你所有本地提交的提交哈希,因为这种改变是通过提交传递的。



由于您已经推送了分支,因此您应该在源分支中进行合并,而不是重新绑定它。可以强制推送你的新分支(使用 -f 标志),但是正常推送不起作用,因为分支历史的完整性将会不安。如果你与这个部门的其他人合作,推动力量是一个不好的主意,因为当他们的历史突然不匹配时,会导致其他合作者变得非常困惑。

TL; DR - 如果您不合作,请使用push -f推分支。如果是这样,请将分支重置为之前的状态,然后在源分支中合并。

I have rebased a branch locally which was already pushed.

Git is advising that my branch and remote have diverged and that:

"and have 109 and 73 different commits each, respectively"

Will pushing my branch resolve this - i.e. is this to be expected after a rebase?

解决方案

When you rebase a branch, you have to rewrite the commits for any commit which is above the commits in the branch onto which you are rebasing. This is because one of the properties of a commit is its parent (or parents). When you rebase, you're changing the parent of the oldest local commit on your branch - and thus changing the commit hashes of all of your local commits, since this change bubbles up through the commits transitively.

Since you'd already pushed the branch, you should have merged in the source branch, rather than rebasing against it. It is possible to "force push" your new branch (using the -f flag), but a normal push won't work, because the integrity of the branches history will be disturbed. If you are collaborating with others on this branch, force pushing is a bad idea, as it will cause other collaborators to become very confused when their history suddenly doesn't match.

TL;DR - If you're not collaborating, push the branch using push -f. If you are, reset the branch to the previous state, and merge in the source branch, instead.

这篇关于Git分支在rebase之后分歧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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