简体   繁体   中英

How do I change the branch I merged into in my previous commit?

I have several branches. They are master, develop, and several feature branches. The structure is like this:

master->develop-> feature branches

so I do everything in the feature branches, then I merge into the develop branch and once I'm done with the program, I release the final version by merging the develop branch into master.

My problem is that way back in my history, I merged one feature branch into the master branch instead of the develop branch. How do I edit that merge, so that the merging branch is done on develop and not master.

I assume it's OK for you to completely rewrite history.

git branch rebase-from ffffff       # 1st commit on master after the wrong merge
git branch last-good rebase-from^^  # commit before the wrong merge on master
git rebase --onto last-good rebase-from master

This will eliminate that wrong merge commit from master. If you have any tags on the old master, they will still point to the original commits after the operation, so the old master might remain visible until the last tag on it. If you want to move the tags as well, you have to communicate it very well to everyone who's ever cloned your repo. Read the DISCUSSION in git help tag about this topic.

Read git help rebase a lot before you start.

Disclaimer: I am not responsible for shooting yourself or anybody else in the foot.

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.

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