Aborting `git stash apply`

GitGit Stash

Git Problem Overview


I regret having applied a stash (wrong branch). How can I undo this and have my stash back to my stash list in order to apply it later on the right branch?

Git Solutions


Solution 1 - Git

If you haven't committed, you should just be able to git stash again, possibly with a git reset HEAD first.

Also, git stash apply doesn't delete the stash like git stash pop does. So if you have committed, you could git reset --hard [last_good_commit] (if you haven't pushed) or git revert [last_good_commit] (if you have pushed) and just apply the stash again once you're on the right branch.

Note: Running git reset --hard will delete any uncommitted code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionabernierView Question on Stackoverflow
Solution 1 - GitBrandanView Answer on Stackoverflow