ShareYourGroupShareYourGroupGit Help

Undo a merge I just made

I merged and it was a mistake.

The problem

I merged and it was a mistake.

How the practice repository looked before

$ git status --short --branch
## main
$ git log --oneline -5
288b521 Merge branch 'feature'
91d2981 Main work
8c6f355 Feature
f45d32e Base

The fix

$ git reset --hard ORIG_HEAD
HEAD is now at 91d2981 Main work

Check the result

$ git log --oneline --graph
* 91d2981 Main work
* f45d32e Base

Why this works

Right after a merge, ORIG_HEAD points at where your branch was before it. Resetting to it removes the merge commit. For a merge that has been pushed, use git revert -m 1 <merge commit> instead.

If this is not quite your case

If the merge stopped on a conflict and you have not committed, git merge --abort is the right command, not a reset. If you already pushed the merge, resetting would rewrite shared history; use git revert -m 1 <merge commit> instead, and know that Git will then treat the branch as merged when you try again, so the changes you reverted are not merged again unless you revert the revert.

Be careful: ORIG_HEAD is overwritten by the next reset, merge or rebase, so use it straight away.

This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.