我想合并到非常不同的 Git 分支。这将是很多工作,因为他们有数百个冲突。
最好的方法是什么,以便其他人也可以帮助我并进行此合并?
通常,我只是在做'git merge ...',然后经历所有冲突,解决它们,然后进行提交。但那只是当地的。
解决冲突的工作可能需要几天时间。我想在我处理它的同时将我的更改放到网上。
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. (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.
From this point on there are mainly two ways to proceed:
git cherry-pick
commits from the outdatedbutcleantopicbranch into upstreambranch's HEAD, starting with the oldest unmerged commit.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.
如果您希望其他人帮助您,则需要将这些分支放在某个可访问的服务器上作为远程分支。
您不必一次完成所有工作。分支在某个时间点出现分歧。所以你从那里开始工作,但逐渐合并提交。
例如,您有 master 分支和非常不同的分支,称为 b。
如果你切换到master并且git merge b
你会遇到很多冲突。
因此,您开始查看 master 和 b 分离的历史记录。然后以 b 分支中的第三次提交为例并将其合并
git merge <sha_in_b_branch>
你只会得到一些冲突。解决它们,提交,将您的更改推送到远程分支,然后其他人可以继续。进行接下来的几次提交,解决冲突,提交推送等。像这样继续,直到你来到 b 分支的负责人。