Undo a Git merge that has not been pushed

Abort an unfinished merge or return to a verified pre-merge commit, accounting for ORIG_HEAD changes, fast-forwards, and current local edits.

Best practices
Illustration of Git branches and version history

If the merge is still in progress, use git merge --abort. If it has finished and its history is still local, find the verified pre-merge tip and reset to it after saving work you need. ORIG_HEAD is often a useful shortcut immediately after a merge, but inspect it first.

Abort an unfinished merge

git status
git merge --abort

This attempts to reconstruct the pre-merge state. Starting a merge with uncommitted edits can make that reconstruction difficult, and conflict-resolution work can be discarded by aborting. Preserve anything you want to keep separately.

Inspect the pre-merge tip

git show --stat ORIG_HEAD
git reflog --date=iso
git log --oneline --graph -10

Merge records the prior branch tip in ORIG_HEAD, but later commands such as reset can replace it. It is not a permanent “last merge” marker or a universal log of every risky operation.

Select the exact old commit from the reflog or another retained reference. This is especially useful after a fast-forward merge: there may be no merge commit whose first parent represents the entire pre-merge position.

Restore the old branch state

Save current edits and preserve the merged commits with an unused backup branch name:

git branch backup-after-merge
# After verifying PRE_MERGE_COMMIT and saving uncommitted work:
git reset --hard PRE_MERGE_COMMIT

Replace the placeholder with the chosen commit ID. Immediately after an inspected merge, git reset --hard ORIG_HEAD may identify the same target, but an explicit verified hash avoids relying on a mutable helper ref.

Verify what changed

git log --oneline --graph -5
git status
git diff PRE_MERGE_COMMIT HEAD

The branch should point to the intended old commit. Tracked files introduced by the merge and absent from the target are removed. Unrelated untracked files generally remain, although untracked paths obstructing tracked restoration can be deleted. Do not add a broad clean command merely because some local files remain.

FAQ

What if the merge was already pushed?

A local reset does not undo a published branch update. For an actual merge commit on shared history, git revert -m 1 MERGE_COMMIT can reverse changes relative to its first parent, provided that is the intended mainline. A fast-forward has no merge commit to revert this way. Inspect the history and choose the appropriate corrective commits.

Will reverting a merge allow me to merge the same changes again later?

Not automatically. The merge remains in ancestry, and the revert changes the tree. Reintroducing those changes later may require reverting the revert or another deliberate integration plan.

Can I keep edits made after the merge?

Save them before resetting. The backup branch preserves committed history only; use a stash or another backup for uncommitted work, accounting separately for ignored files and submodules.

See git-merge, git-reset, and git-revert.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting