Introduction
You stashed some changes earlier and now want to apply them back to your working directory. However, your current working directory has changes that conflict with the stashed changes, causing the stash apply to fail. Git cannot automatically merge these conflicts and requires manual intervention.
Symptoms
When applying a stash:
Auto-merging src/app.js
CONFLICT (content): Merge conflict in src/app.jsOr with more context:
error: could not apply stash@{0} on branch feature
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <file>", then run "git stash drop".When checking status:
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: src/app.jsCommon Causes
Stash apply conflicts occur when: - The working directory has changes to the same lines that were stashed - Files were added, modified, or deleted differently since the stash - The branch you're applying to has diverged from when the stash was created - You have uncommitted changes that overlap with the stash - Multiple stashes exist and you're applying to incompatible state
Git tries to merge but cannot determine which version to keep when changes overlap.
Step-by-Step Fix
Step 1: List Available Stashes
See all stashes and their context:
git stash listOutput shows:
stash@{0}: WIP on feature: abc123 Last commit message
stash@{1}: WIP on main: def456 Another commit
stash@{2}: On develop: fix urgent bugView details of a specific stash:
git stash show -p stash@{0}Step 2: Check Current State
Before resolving, understand what's happening:
git statusSee what files have conflicts:
git diff --name-only --diff-filter=UStep 3: Understand Conflict Markers
Open a conflicted file:
cat src/app.jsYou'll see:
<<<<<<< Updated upstream
const currentCode = 'working directory version';
=======
const stashedCode = 'stashed version';
>>>>>>> Stashed changes<<<<<<< Updated upstream= your current working directory======== separator>>>>>>> Stashed changes= the stashed content
Step 4: Resolve Conflicts Manually
Edit each conflicted file, choosing or combining the changes:
nano src/app.jsChoose one side:
const currentCode = 'working directory version';Or combine both:
const currentCode = 'working directory version';
const stashedCode = 'stashed version';Remove all conflict markers.
Step 5: Stage Resolved Files
Mark each resolved file:
git add src/app.js
git add src/another-file.jsIf you want to discard the stash's version of a file:
git checkout --ours src/app.js
git add src/app.jsIf you want to keep the stash's version:
git checkout --theirs src/app.js
git add src/app.jsStep 6: Complete the Stash Apply
After resolving all conflicts:
git commitNote: The stash apply doesn't create a commit itself; you commit your resolved working directory.
Or, if you had no prior staged changes and just want to keep the resolution:
git resetStep 7: Clean Up the Stash
If the apply was successful and you no longer need the stash:
git stash drop stash@{0}Or drop the most recent stash:
git stash dropStep 8: Abort and Start Over
If the conflicts are too complex, abort the stash apply:
git stash show -p stash@{0} > /tmp/stash-content.patch
git checkout --theirs .
git resetThen apply the stash differently:
# Apply to a clean branch
git checkout -b stash-recovery
git stash apply stash@{0}Step 9: Apply Stash to Clean Working Directory
To avoid conflicts, apply to a clean state:
```bash # Save current changes git commit -am "WIP: Current changes"
# Or stash them too git stash push -m "Current WIP"
# Now apply the other stash git stash apply stash@{1} ```
Step 10: Use git stash pop Instead of apply
If you want to apply and drop in one step (when you're sure it will work):
git stash popThis applies the stash and drops it if successful. On conflict, the stash is preserved.
Verification
Check that all conflicts are resolved:
git diff --checkNo output means no conflict markers remain.
Verify working directory state:
git statusConfirm your changes are as expected:
git diffRun tests to ensure the merge didn't break anything:
npm test
# or
make testPrevention
Before stashing, commit or stage changes:
git add -A
git stash push -m "Descriptive message"Create a branch from a stash instead of applying:
git stash branch stash-recovery stash@{0}This creates a new branch and applies the stash there, avoiding conflicts with your current work.
Related Articles
- [Technical troubleshooting: Fix Git Bisect Skip Marking Bad Commit Incorrectly](bisect-skip-marking-bad-incorrectly-git)
- [Technical troubleshooting: Fix Cherry Pick Range Wrong Order Git Issue in Git](cherry-pick-range-wrong-order-git)
- [Fix Credential Helper Not Storing Wsl2 Git Issue in Git](credential-helper-not-storing-wsl2-git)
- [Fix Git Filter-Branch Rewrite Breaking GPG Commit Signatures](filter-branch-rewrite-breaking-signatures-git)
- [Git Abort Rebase and Recover: Complete Guide](fix-git-abort-rebase)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Git Stash Apply Conflict Resolution Guide", "description": "Learn how to resolve git stash apply conflicts when stashed changes conflict with current working directory", "url": "https://www.fixwikihub.com/fix-git-stash-apply-conflict", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2025-11-18T21:43:39.971Z", "dateModified": "2025-11-18T21:43:39.971Z" } </script>