简体   繁体   English

Git:重做与另一个分支合并

[英]Git: redo merge with a different branch

I have a long-running git fork and I wanted to merge the upstream branch. 我有一个长期运行的git fork,我想合并上游分支。 Unfortunately I did git merge upstream-topic and spent hours resolving merge conflicts before realizing I really wanted to do git merge upstream-master . 不幸的是,我确实进行了git merge upstream-topic并花了几个小时解决了合并冲突,然后才意识到我真的想做git merge upstream-master

The branches have 99% the same content, except upstream-topic has a bunch of merge commits from merging upstream-master that I'd prefer not to have cluttering the history forever. 分支具有99%的相同内容,不同之upstream-topic在于upstream-topic具有来自合并upstream-master的一堆合并提交,而我不希望永久地弄乱历史记录。 Is there any way to "redo" the merge with upstream-master without losing all my conflict resolution? 有什么办法可以“重做”与upstream-master的合并,而又不丢失我所有的冲突解决方案?

I've just discovered git rerere and really wish I'd had it enabled :( 我刚刚发现了git rerere ,真希望我能启用它:(

If the two branches upstream-topic and upstream-master really contain the same content and only differ in those extra merge commits, then you can simply reuse the content of your merged upstream-topic to solve the merge conflicts in upstream-master : 如果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

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

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