What is the difference between git stash pop and git stash apply, and when would you choose one over the other?
Last updated
Both reapply stashed changes to your working tree, but pop also deletes the stash entry afterward, while apply leaves it in the stash list.
git stash pop:Applies then drops the stash (only if the apply succeeds cleanly).
Convenient one-shot restore when you're done with the stash.
git stash apply: Applies but keeps the entry, so you can reuse it (e.g. apply the same stash to multiple branches).When to choose which:
Prefer
applywhen the reapply might conflict; the stash stays safe until you're sure, thengit stash dropmanually.Note: on a conflict,
popdoes not drop the stash, so you won't lose it.
- https://betterstack.com/community/questions/git-stash-pop-and-git-stash-apply-difference/
- https://jtemporal.com/understand-the-difference-between-git-stash-apply-and-git-stash-pop/
- https://www.atlassian.com/git/tutorials/saving-changes/git-stash
- https://git-scm.com/docs/git-stash/2.12.5
- https://www.atlassian.com/fr/git/tutorials/saving-changes/git-stash
- https://www.freecodecamp.org/news/how-to-use-git-stash-to-manage-code/