Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aborting `git stash apply` [duplicate]

Tags:

git

git-stash

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?

like image 928
abernier Avatar asked Feb 11 '12 18:02

abernier


People also ask

How do I abort a git stash?

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.

What happens if you git stash twice?

If you made two stashes, then just call git stash pop twice. As opposed to git stash apply , pop applies and removes the latest stash. You can also reference a specific stash, e.g.

How do I get rid of Applied stash?

Sometimes we may need to undo a git stash apply, maybe we didn't mean to apply it at all or we just applied it to the wrong branch. Update: I've made an easy extension to git that makes this command more easy to remember, i call it gitUndo. With that extension all you need run is: git undo stash-apply.

How do I Unstash changes in git?

To retrieve changes out of the stash and apply them to the current branch you're on, you have two options: git stash apply STASH-NAME applies the changes and leaves a copy in the stash. git stash pop STASH-NAME applies the changes and removes the files from the stash.


1 Answers

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.

like image 106
Brandan Avatar answered Sep 19 '22 22:09

Brandan