git
undo changes
merge conflicts
version control
troubleshooting

Git can't undo local changes error path ... is unmerged

Interview Questions practice on Codemia

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

Browse interview questions

Introduction

The Git error path ... is unmerged means the file is not an ordinary modified file anymore. Git is in the middle of a merge or rebase conflict, and that path has multiple staged versions in the index that still need resolution.

That is why normal undo my local changes commands stop working. Before Git can discard or restore the file, you have to either finish resolving the conflict or abort the operation that created it.

What unmerged Actually Means

During a conflict, Git stores more than one version of the same file in the index:

  • the common base
  • the ours version
  • the theirs version

Until you resolve the conflict and stage the result, Git treats the path as unresolved. Commands such as git checkout -- file or git restore file may refuse to overwrite it because the index is not in a normal single-version state.

You can confirm the situation with:

bash
git status
git ls-files -u

git status tells you which files are unmerged. git ls-files -u shows the separate conflict stages stored in the index.

Option 1: Resolve the Conflict Properly

If you want to keep the merge or rebase and just finish it, resolve the file manually:

bash
git status

Open the conflicted file and remove the conflict markers:

text
1<<<<<<< HEAD
2current branch content
3=======
4incoming branch content
5>>>>>>> feature-branch

Then stage the resolved version:

bash
git add path/to/file

After every conflicted file is staged, continue the operation:

bash
git merge --continue

or, if you are in a rebase:

bash
git rebase --continue

This is the right path when you actually want the merge or rebase to succeed.

Option 2: Abort the Merge or Rebase

If your real goal is undo this whole mess and go back, abort the operation instead of fighting individual files.

For a merge:

bash
git merge --abort

For a rebase:

bash
git rebase --abort

That usually restores the repository to the state before the merge or rebase started.

This is often the cleanest answer when you do not care about the in-progress conflict and just want your working tree back.

Option 3: Choose One Side of the Conflict

Sometimes you do not want a manual merge. You just want ours or theirs for one file.

Use:

bash
git checkout --ours path/to/file
git add path/to/file

or:

bash
git checkout --theirs path/to/file
git add path/to/file

That resolves the file by selecting one side, then stages the result so Git no longer sees it as unmerged.

Be careful with the meaning of ours and theirs during a rebase. The names are consistent technically, but users often misread which side is which in that context.

Why Plain Restore Commands Fail

When a path is unmerged, Git is protecting conflict state. A command that normally restores a file from HEAD assumes there is only one indexed version of that file. In an unmerged state, there are several staged entries, so Git stops and asks you to resolve the ambiguity explicitly.

That behavior is frustrating when you just want to discard changes, but it is correct. Git cannot safely decide which side of the conflict you meant without more information.

A Safe Debugging Sequence

When in doubt, use this order:

bash
git status
git ls-files -u

Then choose one of these paths:

  1. Resolve conflicts and git add.
  2. Abort the merge with git merge --abort.
  3. Abort the rebase with git rebase --abort.
  4. Pick --ours or --theirs for individual files.

That keeps you out of the trap of running increasingly forceful commands without understanding the repository state.

Common Pitfalls

The most common mistake is treating an unmerged path like an ordinary unstaged edit. It is not. The repository is in the middle of a higher-level operation.

Another pitfall is using git checkout --theirs during a rebase without double-checking what theirs represents in that workflow. People often expect the branch names mentally, not the rebase internals.

Users also forget to run git add after resolving a file. Until the resolved file is staged, Git still considers it unmerged.

Finally, do not jump straight to destructive cleanup commands when git merge --abort or git rebase --abort would solve the problem safely.

Summary

  • 'path ... is unmerged means Git is holding multiple conflict stages for that file.'
  • Ordinary restore or undo commands may fail until the conflict is resolved or aborted.
  • Resolve conflicts manually and git add, or abort the merge or rebase entirely.
  • Use git checkout --ours or git checkout --theirs when one side should win.
  • Start with git status so you know whether you are in a merge, rebase, or another conflict state.

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.