Tagged: stash

GIT: How to use stash

- by admin

Git features The Stash, which is as much as a good place to store uncommitted changes. When you stash you changes, the will be stored, and your working copy will be reverted to HEAD (the last commit revision) of your code.

When you restore your stash, you changes are reapplied and you continue working on your code.

Stash your current changes
$ git stash save 
Saved "WIP on master: f12345..."

List current stashes

Yes, you can have more than one!! The stash works like a stack. Every time you save a new stash, it's put on top of the stack.
$ git stash list
stash@{0}: WIP on master: f12345..."

Note the stash@{0} part? That's your stash ID, you'll need it to restore it later on. Let's do that now. The stash ID changes with every stash you make. stash@{0} refers to the last stash you made.

Apply a stash
$ git stash apply stash@{0}

You may notice the stash is still there after you have applied it. You can drop it if you don't need it any more.
$ git stash drop stash@{0}

Or, because the stash acts like a stack, you can pop off the last stash you saved:
$ git stash pop

If you want to wipe all your stashes away, run the 'clear' command:
$ git stash clear

It may very well be that you don't use stashes that often. If you just want to quickly stash your changes to restore them later, you can leave out the stash ID.
$ git stash
$ git stash pop

« All tags