Introduction

When git stash pop encounters a conflict between the stashed changes and the current working directory, Git may abort the operation, leaving the stash in an uncertain state. In some cases, the pop partially applies and the stash is dropped, risking data loss:

bash
git stash pop
# error: Your local changes to the following files would be overwritten by merge:
#   src/config.js
# Please commit your changes or stash them before you merge.
# Aborting
# The stash entry is kept in case you need it again.

Symptoms

  • git stash pop fails with "would be overwritten" error
  • Stash is not dropped (safe) but changes are not applied
  • In some cases, stash is dropped but changes were not fully applied
  • Working directory has a mix of current and stashed changes
  • Cannot determine which version of conflicting files is correct

Common Causes

  • Both the stash and the working directory modified the same files
  • Stash was created long ago and the codebase has changed significantly since
  • Multiple stashes with overlapping changes
  • Stash applied on a different branch than where it was created
  • Working directory has uncommitted changes that conflict with the stash

Step-by-Step Fix

  1. 1.Check if the stash is still available after a failed pop:
  2. 2.```bash
  3. 3.git stash list
  4. 4.# If the stash is still listed, it was not dropped
  5. 5.`
  6. 6.Apply the stash without dropping it (safer than pop):
  7. 7.```bash
  8. 8.git stash apply stash@{0}
  9. 9.# This keeps the stash intact even if conflicts occur
  10. 10.`
  11. 11.Resolve conflicts in the affected files:
  12. 12.```bash
  13. 13.git status
  14. 14.# Shows files with conflicts
  15. 15.# Edit each conflicted file to resolve
  16. 16.git add <resolved-files>
  17. 17.`
  18. 18.If the stash was dropped but not fully applied, recover it:
  19. 19.```bash
  20. 20.# Find the stash commit via reflog
  21. 21.git reflog | grep stash
  22. 22.# Or find unreachable commits
  23. 23.git fsck --no-reflogs --unreachable
  24. 24.# Cherry-pick or merge the stash commit to recover its changes
  25. 25.git cherry-pick <stash-commit-hash>
  26. 26.`
  27. 27.For complex conflicts, apply the stash to a temporary branch:
  28. 28.```bash
  29. 29.git checkout -b temp-stash-recovery
  30. 30.git stash apply stash@{0}
  31. 31.# Resolve conflicts in isolation
  32. 32.# Then cherry-pick or copy the resolved changes back to your main branch
  33. 33.git checkout main
  34. 34.git cherry-pick temp-stash-recovery
  35. 35.git branch -d temp-stash-recovery
  36. 36.`

Prevention

  • Always use git stash apply instead of git stash pop to keep the stash as a backup
  • Commit your working changes before popping a stash to avoid conflicts
  • Create stashes frequently with descriptive messages: git stash push -m "WIP: fixing auth bug"
  • Clean up old stashes regularly: git stash drop stash@{N}
  • Use git stash show -p stash@{0} to preview stash contents before applying
  • Avoid working on the same files across multiple branches simultaneously
  • Consider using git worktree for parallel work instead of stashing
  • For critical uncommitted work, commit to a temporary branch instead of stashing