Mostly, but not always, about developing software.

Tuesday, March 17, 2009

Cherry pickins with git

Git came to my rescue very nicely today by allowing me to replay history a bit. Earlier in the day I had to revert a commit because I got interrupted half way through getting the new changes working on our build server. By the time I got around to having a second attempt, the repository had moved on a number of commits. So I wanted to reverse the revert, but was nervous about losing any of the later changes.

After a few branch-merge and branch-rebase attempts in different directions, a colleague suggested git cherry-pick. Using gitx, I grabbed the sha of the commit that I wanted to re-apply and ran git cherry-pick <sha-to-reapply> (on a new branch from master). This created a new commit as a descendant of HEAD, with exactly the changes I wanted re-applied. It even re-applied the commit message (although next time I'll use the -x option to flag the commit as a cherry pick - should have read the man page a bit closer).

Not only was cherry-pick the right tool, but git allowed me to very quickly branch, merge and rebase any number of times until I found the best way to do the job. Nice.

No comments:

Post a Comment

Twitter Updates

    follow me on Twitter

    Followers