How to fix CONFLICT (content): Merge conflict in file.txt in Git
This error occurs when git stash pop or git stash apply tries to reapply stashed changes that conflict with modifications made to your working directory since the stash was created. The conflict must be resolved manually before you can continue.
Quick fix
Fixes CONFLICT (content): Merge conflict in file.txt
git status- Identify conflicting files
- Open and resolve each conflicting file
- Mark conflicts as resolved
- Drop the stash manually
git statusCONFLICT (content): Merge conflict in file.txt
What this error means
When you run `git stash pop` or `git stash apply`, Git attempts to merge your stashed changes back into your working directory. If the same lines in a file have been modified both in your stash and in your current working tree (or commits made since stashing), Git cannot automatically determine which version to keep. This results in a merge conflict that must be resolved manually. The `CONFLICT (content)` message indicates a content-level conflict where the same section of a file has diverging changes. Git marks these conflicting sections in the file with conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) so you can see both versions and decide how to merge them. Importantly, when a conflict occurs during `git stash pop`, the stash is NOT automatically dropped from the stash list. This safety feature allows you to abort the operation and try again if needed.
Typical symptoms
- git stash pop fails with CONFLICT message
- Files contain conflict markers (<<<<<<<, =======, >>>>>>>)
- git status shows files as "both modified" or "Unmerged paths"
- The stash entry remains in the stash list after a failed pop
- Unable to commit or continue work until conflicts are resolved
Common causes
- The same lines were modified in both the stash and current working tree
- Changes were committed to the same files after creating the stash
- Multiple developers modified the same code sections
- Rebasing or merging occurred between stashing and applying
- Applying a stash to a different branch than where it was created
How to fix "CONFLICT (content): Merge conflict in file.txt"
Run git status to see which files have conflicts:
git statusFiles with conflicts will be listed under "Unmerged paths" or shown as "both modified".
Open each conflicting file in your editor. Look for conflict markers:
<<<<<<< Updated upstream
// Current working tree changes
=======
// Stashed changes
>>>>>>> Stashed changesDecide which changes to keep, edit the file to your desired state, and remove all conflict markers. You can keep one version, the other, or combine them.
After editing, stage the resolved files:
git add <resolved-file>
# Or stage all resolved files:
git add .If you want to unstage and keep working without committing:
git restore --staged .Since the stash was not automatically dropped due to the conflict, remove it manually after successful resolution:
git stash dropThis removes the most recent stash entry. If you applied a specific stash, use git stash drop stash@{n} where n is the stash index.
If you want to undo the stash pop and start over:
# Reset all changes (WARNING: discards uncommitted work)
git checkout -f
# Or for specific files:
git checkout -- <file>The stash remains intact so you can try a different approach.
Advanced notes
Using git stash apply vs pop: Consider using git stash apply instead of git stash pop. The apply command keeps the stash regardless of success, giving you a safety net. You can manually drop it with git stash drop after confirming everything works.
Merge tools: For complex conflicts, use a visual merge tool:
git mergetoolThis opens your configured merge tool (like vimdiff, meld, or VS Code) to help resolve conflicts visually.
Stashing to a branch: If you frequently encounter stash conflicts, consider creating a branch from your stash instead:
git stash branch <new-branch-name>This creates a new branch from the commit where you originally stashed, applies the stash, and drops it if successful.
Partial stash application: Use git checkout stash -- <file> to selectively apply specific files from a stash without triggering a full merge.
Frequently asked questions
- What does "CONFLICT (content): Merge conflict in file.txt" mean?
- When you run git stash pop or git stash apply, Git attempts to merge your stashed changes back into your working directory. If the same lines in a file have been modified both in your stash and in your current working tree (or commits made since stashing), Git cannot automatically determine which version to keep. This results in a merge conflict that must be resolved manually.
- How do I fix "CONFLICT (content): Merge conflict in file.txt"?
- This error occurs when git stash pop or git stash apply tries to reapply stashed changes that conflict with modifications made to your working directory since the stash was created. The conflict must be resolved manually before you can continue.
- What causes "CONFLICT (content): Merge conflict in file.txt"?
- The same lines were modified in both the stash and current working tree Changes were committed to the same files after creating the stash Multiple developers modified the same code sections
- Is the "CONFLICT (content): Merge conflict in file.txt" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Git Official Documentation
- ๐ฌStack Overflow: how to resolve git stash conflict without commit(Stack Overflow)
- ๐
- ๐