Git:重做与不同分支的合并

时间:2015-05-26 06:52:12

标签: git merge

我有一个长期运行的git fork,我想合并上游分支。不幸的是我做了git merge upstream-topic并花了好几个小时来解决合并冲突,然后才意识到我真的想做git merge upstream-master

分支机构拥有99%相同的内容,除了upstream-topic有一堆合并提交来自合并upstream-master,我不希望永远混乱历史。有没有办法在不失去我所有的冲突解决方案的情况下“重做”与upstream-master的合并?

我刚发现git rerere并且真的希望我启用它:(

1 个答案:

答案 0 :(得分:2)

如果两个分支upstream-topicupstream-master确实包含相同的内容,并且仅在这些额外的合并提交方面有所不同,那么您可以简单地重用已合并的upstream-topic的内容来解决合并upstream-master中的冲突:

# save the current master which merged upstream-topic
git branch merged-topic

# reset master to its original commit
git reset --hard origin/master

# do the merge, getting lots of conflicts
git merge upstream-master

# instead of solving those conflicts again, just use all the contents
# of your already merged topic
git checkout merged-topic -- .

# check the status, resolve the conflicts, and commit
git status
git add -u .
git commit