August 7, 2012

Git stashing

Yesterday I had some changes that I was making in the mainline (call it master). I realized that I really wanted to check them into the branch for our Release Candidate rather than committing them to mainline and then cherry-picking the commit. So I found since I hadn't committed the changes I could simply execute:

git stash
git checkout release_candidate
: git stash apply 
The stash took my working directory back to the last commit but took all of my non-committed changes and put them in a safe place (the stash). The second command simple switched my working directory to the branch for the release candidate and then the stash apply command took the last stash and applied it to the working directory.

You can label stashes if you use them a lot in order to help keep them organized and you can even specify which stash you would want if it happens to be a previous stash.

until next time