简体   繁体   English

git:分享合并两个分支的工作

[英]git: share the work of merging two branches

I want to merge to very diverged Git branches together. 我想合并到非常不同的Git分支。 That will be a lot of work because they have several hundreds conflicts. 这将是很多工作,因为他们有几百个冲突。

What would be the best way, so that maybe also others can help me and also work on this merge? 什么是最好的方式,所以也许其他人可以帮助我,也可以合作这个?

Normally, I am doing just the 'git merge ...' and then going through all conflicts, resolving them, then do the commit. 通常,我只是做'git merge ...'然后经历所有冲突,解决它们,然后进行提交。 But that is local only then. 但那只是当地的。

The work on the conflict-resolving maybe can take several days. 解决冲突的工作可能需要几天时间。 I want to put my changes online already while I am working on it. 我想在我工作的时候在网上完成我的更改。

if you want others to help you, you need to put those branches on some accessible server as remote branches. 如果您希望其他人帮助您,您需要将这些分支作为远程分支放在某个可访问的服务器上。

You don't have to do all the work at once. 您不必一次完成所有工作。 Branches diverged on some point in time. 分支机构在某个时间点出现分歧。 So you start working from there but merging commits gradually. 所以你从那里开始工作,但逐渐合并提交。

For example you have master branch and very different branch called b. 例如,您有主分支和非常不同的分支,称为b。

if you switch to master and do git merge b you will get ton of conflicts. 如果你切换到master并执行git merge b你会遇到很多冲突。

So you start looking in history where master and b separated. 所以你开始查看master和b分开的历史。 Then take for example third commit in b branch and merge it 然后在b分支中进行第三次提交并合并它

git merge <sha_in_b_branch>

You will get you only a few conflicts. 你只会遇到一些冲突。 Resolve them, commit, push your changes to remote branch and then somebody else can continue. 解决它们,提交,将您的更改推送到远程分支,然后其他人可以继续。 Takes next few commits, resolve conflicts, commit push etc. Continue like that until you come to head of b branch. 接下来几次提交,解决冲突,提交推送等。继续这样直到你来到b分支的负责人。

When facing this problem recently, I decided to rewind the diverged to-be-merged branch to the last common commit (which I found out with git cherry -v upstreambranch divergedbranch ) and to remove all commits, that I didn't want to merge. 当最近遇到这个问题时,我决定将分歧的合并分支倒回到最后一个常见提交(我用git cherry -v upstreambranch divergedbranch )并删除所有提交,我不想合并。 (I. e. those commits already present in the master branch, if with a different hash.) (例如,那些已经存在于主分支中的提交,如果使用不同的散列。)

So from the list of commits in 所以从提交列表中

git rebase -i --onto lastcommoncommit upstreambranch divergedbranch

I removed all commits that were listed in 我删除了列出的所有提交

git log lastcommoncommit..upstreambranch

The outcome of this is a clean but slightly outdated topic branch containing only commits that aren't already part of upstreambranch. 这样做的结果是一个干净但略显过时的主题分支,其中仅包含尚未成为upstreambranch一部分的提交。

From this point on there are mainly two ways to proceed: 从这一点开始,主要有两种方法:

  1. You could git cherry-pick commits from the outdatedbutcleantopicbranch into upstreambranch's HEAD, starting with the oldest unmerged commit. 你可以从outdatedbutcleantopicbranch git cherry-pick提交到upstreambranch的HEAD,从最古老的未合并提交开始。
  2. Rebase the outdatedbutcleantopicbranch to older states of upstreambranch like git rebase --onto upstreambranch@{4 weeks ago} upstreambranch 将outdatedbutcleantopicbranch重新定位到git rebase --onto upstreambranch@{4 weeks ago} upstreambranch的upstreambranch,如git rebase --onto upstreambranch@{4 weeks ago} upstreambranch

After finishing a rebase/cherry-pick session you push your changes to an integration branch where someone else can continue using the same process. 完成rebase / cherry-pick会话后,您将更改推送到集成分支,其他人可以继续使用相同的过程。

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

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