Tuesday, 13 March 2012

Souce control? What a git!

So, I’ve just started a new job and for the first time I’m using git in a multiuser environment. That means it’s time to start making mistakes :)

Standard practice is to create branches for anything beyond trivial single commit tweaks, and as I’ve been started off with writing tests around some untested legacy type code I’m feeling like lots of small commits is a good idea. After a few of these I realised that I failed to branch, so everything that I’m doing is going into the “trunk” type branch. Ideally I’d like to be able to create a new branch based on the state of the code when I started, move all of my commits onto it and remove them from the trunk, as if I’d created a new branch right at the start.

A quick googling led me to a handy stackoverflow post with the following response:

git stash
git checkout -b edge SHA1_before_your_commits
git rebase master # to replay all your commits on top of this new branch
git checkout master
git reset --hard SHA1_before_your_commits
git checkout edge
git stash apply

The stash commands are just there for work that hadn’t been committed, so I didn’t need them. As a windows developer I’m used to my GUI tools so I’m using git extensions, but found it relatively simple to translate the command line directions. Lo and behold, everything seems to be working as expected. I hope…

No comments:

Post a Comment