0

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?

marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • Give me a history - did you merge `new-ui` and `video-upload` into master? Was it just a straight merge between those two specific branches? And you don't want anything that was on `video-upload` in that branch until you can fix things? – Makoto Sep 02 '15 at 23:38
  • @Makoto So it started with this question - http://stackoverflow.com/questions/32362647/git-rebase-or-git-merge. TL;DR: I have two feature branches, one was forked from the other and work was done on the 2nd as well as the first (after the 2nd was forked). I am trying to merge the changes done on the second back into the first. I went ahead and did that, but now regret it - so I want to revert the merge. How do I revert that merge? – marcamillion Sep 02 '15 at 23:40
  • Check [this answer](http://stackoverflow.com/a/6217372/1079354) out. It feels like this could be a duplicate. – Makoto Sep 02 '15 at 23:42
  • 3
    possible duplicate of [Undo a Git merge?](http://stackoverflow.com/questions/2389361/undo-a-git-merge) – Makoto Sep 02 '15 at 23:42
  • How do I know what the correct `commit_hash` is for the merge? – marcamillion Sep 02 '15 at 23:44
  • You'll have a merge commit in your history. Look through `git log --graph --oneline --decorate --all` to see if you can spot it. – Makoto Sep 02 '15 at 23:46
  • @Makoto So I see multiple lines like this: `| | * | | e28e932 Merge branch 'new-ui' of github.com:me/myapp into video-upload`. Do I look for the outermost/latest one? I am trying to make sense of this all and make sure I choose the right commit. Can you give me some indication of what I should be looking for, because I am just seeing a bunch of the commits of both branches jumped into one. – marcamillion Sep 02 '15 at 23:55
  • @Makoto The differences with all the lines is that the graphic depiction of the branches looks different. So the commit I pasted above, is furthest back in my commit log history (and therefore has more graphics in the illustration). Here is the 2nd furthest back commit `| | * | 490f276 Merge branch 'new-ui' of github.com:me/myapp into video-upload`. Notice that the graphic looks less, i.e. only 1 `|` after the `*` as opposed to `| |` in the one above. – marcamillion Sep 03 '15 at 00:02
  • Paste the result of that log in your question. We can pinpoint when it was merged in that way. – Makoto Sep 03 '15 at 06:36

1 Answers1

-2

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
Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
  • Why all the downvotes? This seems like a reasonable solution...but I can't understand why they are down voting. – marcamillion Sep 02 '15 at 23:38
  • 1
    @marcamillion Beats me! If there are any obvious mistakes, I'd be happy to be corrected, or have my answer copy/paste/modified into something better. Hope _you_ find the answer useful, in any case! :) – Jeff Bowman Sep 02 '15 at 23:44