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:

bash
Auto-merging src/app.js
CONFLICT (content): Merge conflict in src/app.js

Or with more context:

bash
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:

bash
Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
    both modified:   src/app.js

Common 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:

bash
git stash list

Output shows:

bash
stash@{0}: WIP on feature: abc123 Last commit message
stash@{1}: WIP on main: def456 Another commit
stash@{2}: On develop: fix urgent bug

View details of a specific stash:

bash
git stash show -p stash@{0}

Step 2: Check Current State

Before resolving, understand what's happening:

bash
git status

See what files have conflicts:

bash
git diff --name-only --diff-filter=U

Step 3: Understand Conflict Markers

Open a conflicted file:

bash
cat src/app.js

You'll see:

bash
<<<<<<< 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:

bash
nano src/app.js

Choose one side:

javascript
const currentCode = 'working directory version';

Or combine both:

javascript
const currentCode = 'working directory version';
const stashedCode = 'stashed version';

Remove all conflict markers.

Step 5: Stage Resolved Files

Mark each resolved file:

bash
git add src/app.js
git add src/another-file.js

If you want to discard the stash's version of a file:

bash
git checkout --ours src/app.js
git add src/app.js

If you want to keep the stash's version:

bash
git checkout --theirs src/app.js
git add src/app.js

Step 6: Complete the Stash Apply

After resolving all conflicts:

bash
git commit

Note: 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:

bash
git reset

Step 7: Clean Up the Stash

If the apply was successful and you no longer need the stash:

bash
git stash drop stash@{0}

Or drop the most recent stash:

bash
git stash drop

Step 8: Abort and Start Over

If the conflicts are too complex, abort the stash apply:

bash
git stash show -p stash@{0} > /tmp/stash-content.patch
git checkout --theirs .
git reset

Then apply the stash differently:

bash
# 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):

bash
git stash pop

This applies the stash and drops it if successful. On conflict, the stash is preserved.

Verification

Check that all conflicts are resolved:

bash
git diff --check

No output means no conflict markers remain.

Verify working directory state:

bash
git status

Confirm your changes are as expected:

bash
git diff

Run tests to ensure the merge didn't break anything:

bash
npm test
# or
make test

Prevention

Before stashing, commit or stage changes:

bash
git add -A
git stash push -m "Descriptive message"

Create a branch from a stash instead of applying:

bash
git stash branch stash-recovery stash@{0}

This creates a new branch and applies the stash there, avoiding conflicts with your current work.

  • [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>