I have a long-running git fork and I wanted to merge the upstream branch. Unfortunately I did git merge upstream-topic
and spent hours resolving merge conflicts before realizing I really wanted to do 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. Is there any way to "redo" the merge with upstream-master
without losing all my conflict resolution?
I've just discovered git rerere
and really wish I'd had it enabled :(
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
:
# 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.