xlhlvw
Last Updated: February 25, 2016
·
6.341K
· tomkr

Git stash

Sometime you just want to to go back to how things were. You want to merge something, or run some command as it was before you were working on it. Luckily this is really easy with git stash. Just run:

git stash

and your workspace reverts to what it was the last time you committed (except for files not yet tracked by git). Want your changes back?

git stash apply

and you're back where you were, but the change is still in the stash.

git stash pop

applies your stashed changes, and removes from the stash as well, so everything is exactly as it was. (Thanks @mordhak for the clarification.)

In a sense it's like doing a temporary commit that you then roll back. But you don't have to write a commit messages or do anything complicated. It's just an easy way to get a blank slate, and fill it right back up.

There's more fancy stuff you can do with the stash as well. You can read more in the Git book

2 Responses
Add your response

9163

Hi,

in your example with git stash, I would have used git stash pop instead of git stash apply in order to retrieve "the same state" than previously. pop removes the last stash from the stash list, apply doesn't.

over 1 year ago ·
9164

Wow, thanks. I know the stash is a stack, but I never used it more than one level down, but I'll change this.

over 1 year ago ·