Skip to content

Very crash course on Mercurial

by Tomek on May 23rd, 2010

Even in small, homebrew projects driven by only one individual, version control system is very welcome. You have vide variety of options to choose from, but in my research i limited myself to ones I know, or at least heard good opinion.

CVS is getting obsolete now, it is outperformed by younger brothers and missing some very useful features.

Subversion (SVN) smells much better, I use it everyday in my day job. Think of it like a CVS on steroids. Branches and tags are cheap. Renames are supported (unlike CVS). Popular and widely supported.

Git has been recetly very popular in open source community, I notice that many of open source libs I download from GitHub. Once reluctant, I now managed to install git client and learned that "checkout" is now called "pull" :-)

Mercurial's name sounds totally strange, but I decided to give it a try as a candidate for my private SCM. Think of it like Git on steroids: well documented, written in Python, so it is ultraportable, and as a bonus there is free, graphical client for Mac OS X - Murky.

Git and Mercurial represent distributed family of version control systems. In simple words, that means that local working copy has features of repository - you can commit, rollback, create tags, branches or however it is called. SCM plays role of source code backup. It that is not a requirement for you - in my case I have backup work managed by Time Machine.

Introducing Mercurial to existing project

First of all, let's configure Mercurial user name to stop hg from complaining. Create .hgrc in you home directory (type hg help config for hit what actually is a home directory in your OS). OS X and Linux users may type

tomek$ vi $HOME/.hgrc

Configuration file is M$ INI-style filename, for start we just enter our username:

[ui]
username = Tomek Cejner <do not want any spam@japko.net>

Making a project a repository is actually a piece of cake. Just enter the directory where project resides and:

tomek$ hg init

Mercurial does not try to reinvent a wheel, so command set is well known for all users of SVN and CVS. Just use intutition:

tomek$ hg add *
tomek$ hg commit

And voila! Your project is version-controlled. No remote repository setup needed. No hassle with configuration. You can move your work to remote, safe repository at any moment later. Let's verify what do we have:

tomek$ hg summary
parent: 0:e64337dfc589 tip
Initial commit
branch: default
commit: (clean)
update: (current)

"Tip" is actually synonym for HEAD (sure, Mercurial devs didn't want to make it so similar to SVN :) . Initial commit is my first comment, and project looks untouched.

This post was intended to be a quick intro, with slight note of evangelism to tell that despite of weird name, Mercurial is very programmer-friendly tool and quick to adopt.

For those uncertain, here is a nice comparison of most popular SCMs.

One Comment
  1. Another bonus of using Mercurial is that http://www.bitbucket.org now has free unlimited repositories for small teams. I’m a one-man team so I’m very happy about the new offer. Teams of five or less can now share unlimited public OR private repositories there as well.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

Comment spam protected by SpamBam