简体   繁体   中英

How do I revert a git merge that had many commits

I have two branches new-ui and video-upload and I am trying to merge them. Before merging them though, I should have created a new branch that holds the result of both....to make sure that the merge result is what I am looking for. I didn't, so I would like to reverse the entire merge (ideally without having to go back through the logs and do it manually).

Both branches, post the fork, have had changes/commits applied to them. So, as you can imagine, the history of both is quite messy.

I want to just revert new-ui to the state it was at before I just merged video-upload to it. Then I can go ahead and create a new branch then do the merge there.

What's the best way to do this?

Git has two helpful properties here: Your merge commit links to both of its parents ( new-ui and video-upload both before the merge), and even if it didn't, git is very conservative about deleting history. If all you're trying to do is to undo the merge, you have a few options to find the commit you're looking for:

  • git log new-ui to see the combined history of new-ui
  • git reflog to see the history of what you've checked out, particularly handy if no name or branch points to it

And then a couple of options to make new-ui point to it again:

  • git checkout YOUR_COMMIT_HASH -B new-ui , which will make new-ui point to YOUR_COMMIT_HASH intead of whatever it was pointing to before
  • git reset --hard YOUR_COMMIT_HASH , if you already have new-ui checked out, which will get rid of any local changes, check out YOUR_COMMIT_HASH, and point the current branch (new-ui) at it

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