Wednesday, January 23, 2008

Refactoring without branching

Developers using the conventional Subversion source control management system (SCM) often come to a point where they cannot continue committing their work on trunk because their changes are impacting the work of others. When you're knee-deep in the code, you don't necessarily plan to create a branch beforehand. A refactoring is sometimes unforeseen, and once you realize it's going to be the big blast of the month, you refrain from committing your work to trunk and realize you'll have to decide: either to keep a huge set of modified files for several weeks at your own risk, or to create a branch and redo your changes there, with all the hassle of managing branches with Subversion (did you ever find yourself entering into endless discussions about branching?). Either way, you feel bad.

Fortunately, there's a new player in the world of source control: GIT.
Git is a popular version control system designed to handle very large projects with speed and efficiency. Git falls in the category of distributed source code management tools. Every Git working directory is a full-fledged repository with full revision tracking capabilities, not dependent on network access or a central server.

Sounds great, heh? But there's no chance your CTO will stash SVN and adopt Git. This is where git-svn comes to the rescue! In a word, git-svn is a bridge between Subversion and Git:

  1. You create a Git workspace by importing the SVN repository once

  2. Make changes and commit them locally in your Git workspace

  3. Repeat step 2. ad lib.

  4. Push back your changes to SVN when you're done

I'm using this approach since a few weeks at work with success. When I push back my changes once a week to the SVN repository, a bunch of commits are made within in a few seconds, that's impressive! My colleagues know when I'll be pushing the next changes, so they can work safely until the next iteration. No more branches, no more hassle, only happy refactoring!

If you want to know more, I suggest to look at:

1 comment:

Anonymous said...

That's a good trick. I will use it with sourceforge svn which does not allow merging branches at all.