How to undo a git merge squash?
If you run git merge --squash <other-branch>
the working tree and index are updated with what the result of the merge would be, but it doesn't create the commit. All you need to do is to run:
git commit
However, if you change your mind before committing and just want to abort the merge, you can simply run:
git reset --merge
You don't need to use the reflog.
If you change your mind before committing, you have these options:
Abort the merge with modern git syntax:
git merge --abort
And with older syntax:
git reset --merge
And really old-school:
git reset --hard
But actually, it is worth noticing that git merge --abort
is only equivalent to git reset --merge
given that MERGE_HEAD
is present. This can be read in the git help for merge command.
git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.
After a failed merge, when there is no MERGE_HEAD
, the failed merge can be undone with git reset --merge
but not necessarily with git merge --abort
, so they are not only old and new syntax for the same thing. Personally I find git reset --merge
much more useful in everyday work.