简体   繁体   中英

Revert to before a merged branch

I have my master branch, then I was working on a another feature, merged this to my local master and then pushed this to Github.

Now I need to remove all changes that happened as a result of this merge, until further notice, but be able to merge them back in at a later point in time.

How can I achieve this?

You have to figure out which of the pre-merge commits represents the "mainline", ie the part that you want to keep. You can do this using git log :

commit b556759a560650506da58e59f6a7c6a2c4bcb8f4
Merge: e3dac0d 090ad85

... and visual inspection of the two parent commits. (It appears that git merge foo will always put HEAD in the first position of the list of parents and the head of foo second, but I'm not sure if this is guaranteed.)

Suppose e3dac0d is the mainline, so we want to revert the merging-in of 090ad85 , then that's

git revert -m e3dac0d b556759

For more details, see the revert a faulty merge howto by Torvalds and Hamano.

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