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.
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
oursversion - the
theirsversion
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:
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:
Open the conflicted file and remove the conflict markers:
Then stage the resolved version:
After every conflicted file is staged, continue the operation:
or, if you are in a rebase:
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:
For a rebase:
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:
or:
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:
Then choose one of these paths:
- Resolve conflicts and
git add. - Abort the merge with
git merge --abort. - Abort the rebase with
git rebase --abort. - Pick
--oursor--theirsfor 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 unmergedmeans 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 --oursorgit checkout --theirswhen one side should win. - Start with
git statusso you know whether you are in a merge, rebase, or another conflict state.
Related reading
- Git checkout updating paths is incompatible with switching branches
- Git Checkout warning unable to unlink files, permission denied
- git cherry-pick says ...38c74d is a merge but no -m option was given
- git cherry-pick says ...38c74d is a merge but no -m option was given
- Git commit opens blank text file, for what?
- Git Corrupt loose object
- Git Cherry-Pick to working copy without commit
- Git Cherry-pick vs Merge Workflow
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.