Stashing with Git
I use Git fairly extensively and one of the features I use and love is stash.
The stash command allows you to take point-in-time snapshots of development
and “stash” 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: $ git stash
This will “stash” 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 git stash pop to add back
in my changes. $ git cherry-pick 9cc0589 $ git stash pop
This will re-apply
my stashed changes on top of the new commit and remove the stash. If this
causes conflicts then you need to edit them by hand. You can store more than
one stash too - the last operations will just pluck the last stash from the
list - but you can store a collection. You can see what stashes are available
by using: $ git stash list stash@{0}: WIP on features/master/dailytask: 2d74623... Added daily build task to Rakefile stash@{1}: WIP on features/master/dailytask: 2d74623... Added daily build task to Rakefile stash@{2}: WIP on master: f13f08d... Minor fix to URL for LDAP nodes documentation
You could then apply a particular stash by specifying the
stash’s ID. $ git stash pop stash@{2}
You can see more features and options
at the git-stash man page.