git
version control
git merge
conflict resolution
programming tips

How to undo a git merge with conflicts

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Undoing a merge with conflicts depends on how far the merge got. If the merge is still in progress and has not been committed, the usual answer is git merge --abort. If the merge was already committed, you need a different strategy.

That distinction matters because Git is protecting two different states: an unfinished merge in your working tree, or a merge commit already recorded in history. The right undo command changes with the state.

Case 1: Merge In Progress, Conflicts Unresolved

If you ran git merge, conflicts appeared, and you want to stop and go back to the pre-merge state, use:

bash
git merge --abort

This is the normal safe answer for an unfinished conflicted merge. It tells Git to restore the branch to the state it had before the merge started.

Before doing that, inspect the state:

bash
git status

If Git reports that a merge is in progress, git merge --abort is the right first move.

Case 2: Merge Commit Already Created Locally

If you already resolved conflicts and committed the merge, then git merge --abort no longer applies because the merge is finished. If the merge commit is still local and you want to discard it completely, one common option is:

bash
git reset --hard ORIG_HEAD

This resets the branch back to where it was before the merge began.

That is destructive for local uncommitted work, so use it only when you are sure you want to throw away the merge result.

Case 3: Merge Already Pushed

If the merge commit has already been pushed and other people may have pulled it, rewriting branch history is usually the wrong move. In that case, revert the merge:

bash
git revert -m 1 <merge_commit_hash>

The -m 1 tells Git which parent should be treated as the mainline. This creates a new commit that undoes the merge without rewriting published history.

How To Check Which Situation You Are In

Use these commands:

bash
git status
git log --oneline --graph --decorate -n 10

Interpret them like this:

  • merge in progress and uncommitted: abort
  • merge committed but local: reset if safe
  • merge committed and pushed: revert

That simple decision tree avoids a lot of panic-driven mistakes.

What Happens to Conflict Markers

If you abort an in-progress merge, Git removes the conflict state and restores files as they were before the merge started. If you already committed the merge, conflict markers no longer matter because the merge result is now just ordinary committed content.

So conflict markers themselves are not the issue. The issue is whether the merge is still a temporary state or already part of history.

Common Pitfalls

  • Using git reset --hard when the merge is still in progress and git merge --abort would have been safer.
  • Trying git merge --abort after the merge was already committed.
  • Rewriting history on a pushed branch instead of reverting the merge.
  • Forgetting to inspect git status and git log before choosing the undo strategy.
  • Losing unrelated local changes because a destructive reset was used casually.

Summary

  • If the conflicted merge is still in progress, use git merge --abort.
  • If the merge commit exists only locally and you want to discard it, git reset --hard ORIG_HEAD may be appropriate.
  • If the merge was already pushed, prefer git revert -m 1 <merge_commit>.
  • Always check whether the merge is unfinished, committed, or published before undoing it.
  • The correct undo method depends on Git state, not just on the word "conflicts."

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.