gitgithubversion-controlmergegit-branch

How to undo merge of master branch?


I'm new Github so please forgive what may seem like an obvious question. I have an Experimentation branch which is 24 commits ahead of the master branch.

Following this tutorial, I merged the master branch with the Experimentation branch like so:

git checkout master
git merge Experimentation

(There were no merge conflicts.)

But then I realized that merging the two branches would not keep the commit history of the Experimentation branch and what I really wanted was to do a rebase (in order to keep the commit history of the Experimentation branch).

So my question is: how do I undo the merge of the master branch?

I've already tried:

$ git branch
      Experimentation
    * master
      pod-attempt

$ git merge --abort
      fatal: There is no merge to abort (MERGE_HEAD missing).

The "fatal" message confused me b/c I thought I did merge the master branch.


Solution

  • There is no ongoing merge pending so git is supposed to show you,

    fatal: There is no merge to abort (MERGE_HEAD missing).
    

    Now if you want to go back to previous state (state before you merged), try

    $ git branch
          Experimentation
        * master
          pod-attempt
    $ git reset --hard HEAD~24 
    

    24, cause OP wants to go ahead of 24 commits.

    You are done!