Stashing with Git

August 2nd, 2009 by kartar Leave a reply »

I use fairly extensively and one of the features I use and love is . The command allows you to take point-in-time snapshots of development and “” them away. The source tree is then returned to the current commit.

So let’s take a quick example. Stashing is something I particularly do when I want to pull changes into a dirty tree.  I am working on a problem and someone over there has committed something that changes the environment. I don’t want to commit my half-done work but I do want to keep it whilst I add the other commits into my tree.  So I type:

$

This will “” away the changes in my dirty tree and leave it clean at the last commit.

I can then, for example, cherry-pick in a commit and then use pop to add back in my changes.

$ cherry-pick 9cc0589
$ pop

This will re-apply my stashed changes on top of the new commit and remove the . If this causes conflicts then you need to edit them by hand.

You can store more than one too – the last operations will just pluck the last from the list – but you can store a collection. You can see what stashes are available by using:

$ list
@{0}: WIP on features/master/dailytask: 2d74623... Added daily build task to Rakefile
@{1}: WIP on features/master/dailytask: 2d74623... Added daily build task to Rakefile
@{2}: WIP on master: f13f08d... Minor fix to URL for LDAP nodes documentation

You could then apply a particular by specifying the ’s ID.

$ pop @{2}

You can see more features and options at the git-stash man page.

Leave a Reply