简体   繁体   中英

How to revert the merge after rebase merged commit?

I merged the branch from test to master. Then i need to revert it but i can't revert merged commit so i do rebase. But after the rebase branch still show as a merged i can't see branch difference. What is the possible way to fix this?

If you want to undo the merge, and if rewriting history is ok in your situation:

  1. Make sure you have a backup of your repo (just in case). Just copy the whole directory.

  2. Find the commit hash on the master branch for the commit just before the merge. Let's call it xyz .

    This git log command makes it easy:

     git log --graph --all --pretty="%C(dim yellow)%h %C(dim cyan)%cd %C(auto)%d%C(reset) %s"

  3. Do this: git branch -f master <xyz> .

  4. Make sure everything is as you want it:

    • look at the updated history (eg using my git log command above). It should no longer show a merge.
    • checkout master, and make sure it is how it should be. You can also run git log --oneline from this context for one final verification.
  5. If you had previously pushed the merge master to a remote, you can overwrite that with git push -f (adding whatever other params you used in the push command before).

    ⚠️ BE AWARE: you are rewriting history and this may impact other users who have already started doing work on the merged master.

  6. When you are sure everything is as they should be, and nothing wanted has been lost, delete your backup copy. But it doesn't hurt to keep it around for a couple of weeks until you are sure.

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