我有一个长期运行的git fork,我想合并上游分支。不幸的是我做了git merge upstream-topic
并花了好几个小时来解决合并冲突,然后才意识到我真的想做git merge upstream-master
。
分支机构拥有99%相同的内容,除了upstream-topic
有一堆合并提交来自合并upstream-master
,我不希望永远混乱历史。有没有办法在不失去我所有的冲突解决方案的情况下“重做”与upstream-master
的合并?
我刚发现git rerere
并且真的希望我启用它:(
答案 0 :(得分:2)
如果两个分支upstream-topic
和upstream-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