Aborting a Merge
Sometimes you start a merge, see the conflicts, and decide you’d rather come back to this later. Git makes it easy to bail out cleanly — git merge --abort undoes the merge in progress and restores your working directory and index to exactly the state they were in before you ran git merge.
The basic abort
Cancel a merge in progress
git merge feature-x # CONFLICT in src/login.js (etc.) # (you decide not to deal with this right now) git merge --abort # Working tree restored to pre-merge state
What --abort does
Removes the in-progress merge state (no more
MERGE_HEAD,MERGE_MSG, etc.).Resets the index and working directory to the commit you were on before
git merge.Discards any conflict markers, partial resolutions, and staging done since the merge started.
When --abort can fail
If you had uncommitted changes before the merge AND the merge tried to overwrite them — those changes may not be perfectly restorable.
Old Git versions (pre-1.7.4) did not have
--abort. Usegit reset --mergeorgit reset --hard HEADinstead.
The legacy fallback
Older Git or stubborn merge
git reset --merge # Equivalent to --abort # Last resort — nuke everything and start over git reset --hard HEAD
Aborting after partial resolution
Even if you already resolved some conflicts and ran git add, --abort still works:
Half-resolved, still bail out
# Resolved 3 of 8 conflicts, then changed your mind: git merge --abort # The 3 resolutions are discarded. You're back to pre-merge.
Aborting a pull (which is fetch + merge)
Same idea
git pull origin main # CONFLICT... git merge --abort # (or: git pull --abort on modern Git)
What if you already committed the merge?
--abort only works during a merge — between the conflict and the commit. Once you’ve committed the merge, the merge is done. To undo a completed merge:
Undo a completed merge
# If the merge was the most recent commit and nothing has happened since git reset --hard HEAD~1 # This destroys the merge commit; your branch goes back to before the merge # Or, more safely (especially after pushing): git revert -m 1 <merge-commit-hash> # Creates a NEW commit that undoes the merge # The -m 1 flag tells Git which parent to keep
Aborting a rebase
Different command, same idea
git rebase --abort # Cancels an in-progress rebase, restores pre-rebase state
Aborting a cherry-pick
git cherry-pick --abort # Cancels an in-progress cherry-pick
How to tell whether a merge is in progress
git status # If you see "You have unmerged paths", a merge is in progress. ls .git/MERGE_HEAD # Existence of this file means a merge is in progress
git merge --abort, take a breath, think about whether you actually need to merge right now, and try again later — possibly with smaller branches.