17 Apr, 2009

Published at 08:53AM

Tagged with git, tips, and version-control

This post has 2 comments

Git stash

This isn’t anything new, or anything complex. But it’s handy, and for those who don’t know about it, well, you should know about it.

Have you ever been working on some code to build the next whatever-feature, and during that process, you realize some other bug that needs fixed, but isn’t necessarily a part of your whatever-feature? Here’s an alternative to handle that situation:

1
2
3
4
$ git stash
[fix the bug]
$ git commit -a -m "bug is now fixed"
$ git stash pop

git stash saves your changes and gives you a clean tree. Then you can do whatever it was you wanted to do (in this case, fix the bug) and commit it. git stash pop brings your changes back, and you can continue as if nothing ever happened. Sweet.

Comments

Chris Scharf Friday, 17 Apr, 2009 Posted at 10:36AM

git stash is very useful when working with git-svn – sometimes I need to rebase before I push to svn, so I usually git stash, git svn rebase, and then git stash apply. Also note that you can name your stashes: git stash save fixing_user_model.

Ben Thursday, 28 Jan, 2010 Posted at 07:54PM

@Chris:
If you develop in a separate branch to master, you shouldn’t need to stash your changes before you rebase.

1. git branch -b in-progress Moves to a new branch
2. [WORK WORK WORK]
3. git checkout master takes you back to the version before your changes
4. git svn rebase pulls down new changes from svn
5. git merge in-progress applies your changes back to master
6. git svn dcommit commits master

Do you have something to say about this post?
Retype the image to the right Spam Hint: Are You Human? Textile Formatting Tips

or

Ryan Heath | Site Management A Ruby on Rails production.

This site is a Formed Function. Formed Function LLC | @formedfunction | Get in Touch