25 Mar 2010

Moving from Subversion to Mercurial


I’ve been using Subversion for the last 5 years and it has served me well. I can’t conceive writing any meaningful code without using it. Using a source control tool is the definitive backup tool for your code and you should be using one no matter what.

Because I work mostly alone, merging has never been a real issue for me. Mainly because I rarely branched my code to work on different branches in parallel.

I used to have just a main branch (trunk) where I add new code. When the code it’s ready to release, I tag it and branch it. Then I continue to add code to the trunk. The branch is used only for maintenance of the shipped code.

When I touch code in the maintenance branch I can merge with the trunk or usually just fix the code in the trunk manually.

That’s it. No branches per feature, usually no experimental branches, life was easy.

However, as some of my projects begun to get momentum (read ‘get real paying customers’), my needs started to grow.

Now I have to have more than one active maintenance branch. I also need branches to develop some custom modules for some customers, and as my time to develop a single feature grows I also need branches to develop features that need a long time to complete.

If you branch a lot you have to merge a lot.

This implies that if you have problems merging you’ll try to avoid branching, and if you can’t branch as needed your source control tool is failing you.

I’ve been avoiding branching in subversion because the merging is sometimes complicated. More than once I end up applying changes manually or overwriting files from folder to folder. Not fun.

I started paying attention to all the buzz about git and its branching/merging model. I installed it and played with it. I saw the benefits but I find some concepts difficult to grasp, so I continued to use subversion while playing with git. Then I found hgInit, a Mercurial tutorial by Joel Spolsky. Turns out that Mercurial it’s pretty much like git, but simpler.

There are some differences that I’m not going to describe here, but they are not as important as their similarities. The key here is that merging code works great!

If you are using subversion please take a look at Mercurial or git. They are a really a big step forward. They have a different model than subversion so it takes a while to grasp the difference between a centralized and distributed source control system, but it’s worth it.

Here are some links that helped me see light:


Linus Torvals on git