Mercurial

Mercurial is a version control system (VCS) from a newer generation of systems than the very popular subversion (SVN). It has good documentation on the project website, and also an online book at http://hgbook.red-bean.com/ for in-depth refernce. From what I can tell it is very similar to another popular VCS program, Git.

Mercurial has a number of advantages compared to SVN, in particular that it is distributed rather than centralised, so there is no need to maintain a master copy of the repository. Instead, every clone of the repository is a fully self-contained repository containing all of the revision history, and can itself be used as a "master copy" to make clones from. This also creates problems with people making conflicting changes, but Mercurial is designed to make the merging of different revisions much easier than was the case with SVN.

Jump to the following sections:

Create a new repository

Creating a new repository is very easy, because it doesn't have to be in a central location. If you have a few files in a project directory, just go to the root directory of the project and type

hg init
Then go through the project and type
hg add [filename]
for each file you want to add (note that mercurial doesn't care about adding directories; it just adds the path to the file and creates whatever directories it needs).


Commiting changes to repository

To commit the changes (i.e. the files you have added) it is similar to SVN:

hg commit -m "Added files to new repo."
Note that this just adds the changes to the directory .hg in the project's root directory. The changes have not been backed up anywhere.


Copying the Repository

If you want a copy of the repository somewhere else, you use the clone command. This can put the cloned repository pretty-much anywhere. For example on the local machine:

    $ hg clone /path/to/project/ /path/to/cloned/project/
    $ cd /path/to/cloned/project/
    $ hg update 

The hg update command is important. Without this, clone just creates the hidden directory .hg/ (which contains all the revision information for the files) in the cloned project directory. When hg update is run, this updates all of the files (in this case it has to create them!) in the cloned project to the latest version. A nice feature is that you can also clone to remote systems, via http, https, or ssh, for example:

    $ hg clone ./projects/my_hg_project/ ssh://user@other.computer.ie/incoming/test
    user@other.computer.ie's password: 
    user@other.computer.ie's password: 
    searching for changes
    remote: adding changesets
    remote: adding manifests
    remote: adding file changes
    remote: added 3 changesets with 33 changes to 32 files
    $ 

Here the remote directory seems to be relative to the default login directory (for me it was my home directory on other.computer.ie). Again the directory test will be empty except for the .hg/ directory, so you need to go into it and run hg update to create the files.

The opposite process also works, where you clone a remote repository to a local directory, by interchanging the order of the paths in the hg clone command above (NOT TESTED!).


Pushing and Pulling

Each cloned repository is completely independent of all others, so you can commit many sets of revisions that the other repositories are unaware of. In this sense Mercurial is fundamentally different to SVN, because for SVN the commit command updates the master copy with a new revision that all other copies can automatically see and update. Mercurial has two new commands to deal with this extra layer, push and pull, to communicate new revisions to and from other cloned repositories. They work just like hg clone, except that if there are conflicts (because there may be independent revisions committed in both repositories) it will say something. Also push and pull only work on the current directory -- you must be in the directory of the cloned repository that you want to push somewhere else. Here I push to a clone that has no new changes, so there are no warnings:

    $ hg push ssh://user@other.computer.ie/projects/my_hg_project/
    user@other.computer.ie's password: 
    pushing to ssh://user@other.computer.ie/projects/my_hg_project/
    searching for changes
    remote: adding changesets
    remote: adding manifests
    remote: adding file changes
    remote: added 1 changesets with 1 changes to 1 files
    $ 




Valid HTML 4.01 Transitional