I have always thought that subversion is most awesome. However, for the past couple of months I have been using Mercurial for some projects and its benefits are beginning to glow ever so brightly. Even more than subversion. Subversion (SVN) is great for linear configuration management and centralised version control whereas Mercurial takes it a step further and allows for distributed version control. I’m not going to take you through a tutorial on the awesomeness of Mercurial. If you want to learn more about Mercurial, Joel Spolsky provides a great explanation/tutorial here. Instead, I would like to show you how you can still claim the benefits of Mercurial even if your existing codebase exists on SVN.
Recently, I came across the problem where I had an existing project with a huge amount of history stored on an SVN repository and I needed to do development work on that project on a computer disconnected from the central SVN repository. So how do you get Mercurial working with SVN?
SVN With Mercurial
You will obviously need to have Mercurial installed. I generally use Mercurial with Tortoise Hg. But I’m sure you’re wondering by now how we will be achieving version control with the existing SVN repository. Luckily there is SVN-Mercurial interoperability.
- Allow for active development of codebase on computer connected to projects SVN repository.
- Allow for parallel development of the codebase on a computer that is disconnected from the central SVN repository.
- Maintain version control on disconnected development environment.
- Merge changes made on remote computer to changes made on connected computer.
- $hg clone svn+http://my-svn-repository/projectX # this will clone projectX from the SVN repository into a Mercurial (Hg) repository.
- Move the cloned repository onto the remote system.
- Do some changes, commit those changes, do some more changes and commit them… meanwhile another developer is happily working and committing to the main SVN repository… but all is fine and dandy.
- After changes have been made on remote computer. Copy Hg repository back to connected computer, OR get current computer an established connection to the SVN repository.
- $hg pull #pull changes from SVN repository into current hg repository.
- $hg merge #merge changes made by parallel developer. Resolve any conflicts.
- $hg commit #commit merged changes to local hg repository.
- $hg push #push changes from local hg repository back to subversion**
**NOTE: In lieu of “hg push” you could also create an SVN patch, $hg di -b -r svnrev([head rev#]):tip > mybugfix.patch.