简体   繁体   中英

How take a merged branch out of a master branch (Github)?

I worked on a branch in my Rails app, committed, and merged it into my master, because I was happy with everything, but now I want to take out that branch again and discard those changes.

Is it possible or too late now that I have merged the branch with the master?

Thanks

You could do a git reset . This is fine if it was only a recent local merge.

If you already pushed the merge somewhere or you have more commits on top, this is no good idea. Instead you have to accept your merge and do a clean git revert . This way the history still contains the merge but the revert will undo the effect of the merge.

Once you have pushed commits to a central location, it's best not to modify them in any way.

An alternative is to generate a reverse commit. That is, a commit that undoes all the changes in a previous commit. One way is git-revert . Assuming that you've merged in commits <sha2> , <sha3> and <sha4> , you could:

git revert <sha4>
git revert <sha3>
git revert <sha2>

If you'd like to revert all changes in a single commit, try the --no-commit option:

git revert --no-commit <sha4>
git revert --no-commit <sha3>
git revert --no-commit <sha2>
git commit -m "Undid feature merge"

Another way to generate a single reverse commit is git checkout :

git checkout -f <sha2>
git commit -a -m "Undid feature merge"

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