Search code examples
gitgit-mergegit-stashgit-revert

Undo git Auto-merge


After I switched branches, I applied stash (as below), which resulted in an auto-merge.

  git stash apply

Auto-merging src/clojure/project_src.clj
On branch upgrade_project
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

modified:   src/clojure/project_src.clj

no changes added to commit (use "git add" and/or "git commit -a")

I tried git revert HEAD which reverted a commit (not the auto-merge). How can I revert the auto-merge?


Solution

  • To abort the merge, you could have done

    git merge --abort
    

    But now that you reverted your last commit, and unless you already pushed that failed state to remote, I'd suggest reseting to the point where you were before the first bad stash :

    git reset --hard HEAD^
    

    At this point you can retry the stash apply and merge it differently, or just not apply the stash, but in any case you're back to square one.