How to reset to the state before a merge was committed?

I’ve resolved some conflicts and committed a merge. Is it possible to restore exactly the merge state that was before running git commit, not changing the index or the working tree? For regular single-parent commits, the command which does this is git reset --soft HEAD^, but for merge commits it doesn’t work as expected, because there is no single parent to reset to.

  • Can a local Git clone be considered a complete backup of the repo it was cloned from?
  • Git rebase when previous commit changed
  • Git - how to list ALL objects in the database
  • clone a branch from GIT
  • Creating a git alias to append to .gitignore
  • git diff/log and the order of start/end commits specified
  • How to retrieve Git commit id and message in VSTS/TFS build?
  • Preventing a file from commiting in git
  • Error cannot stat upon git pull
  • How to programmatically configure a Git branch's description?
  • Git Post Hook to Kick Off Jenkins Job
  • Git: can't push {n/a (unpacker error)}
  • 3 Solutions collect form web for “How to reset to the state before a merge was committed?”

    I don’t think this is supported, but you can fake it by doing git reset --soft HEAD@{1} and then writing the commit id that you were merging to .git/MERGE_HEAD.

    You’ll lose the commit message, though (“Merge commit ‘cafebab’ into HEAD”).

    You have a commit-sha for your merge state. Find the commit by git log or, git reflog command.

    $ git reflog                       # copy the commit-sha of merge state
    $ git reset --soft <commit-sha>
    $ git status                       # see the undo changes

    N.B. If you do --soft reset then the changes of the commits you back exists in your working directory.

    git reset --soft HEAD^ is a synonym for git reset --soft HEAD^1 which means reset softly to the first parent. If it is the second parent (second parent != grandparent, that would be HEAD~2) you want to reset to, use git reset --soft HEAD^2. Alternatively you can of course also do git reset --soft @{1} which means the first entry in the reflog of the current branch if the merge was the last thing you did.

    Git Baby is a git and github fan, let's start git clone.