Places To Find Help

Mercurial is a free, open source distributed version control system (DVCS). Unlike centralized revision control systems, DVCS systems offer a great deal of flexibility and facilitate working productively even in absence of a central server or network connection. However, they are also more complicated than centralized systems, and require a little bit more knowledge to use.

The official page for Mercurial has downloads and an official workflow guide. The official Mercurial Wiki also has a variety of Tutorials, Quick Start guides, and the official Book.

For Microsoft Windows users, I recommend TortoiseHg as a client for Mercurial.

For quick reference on commands and their options you can type hg help.

Grabbing Repository Clones

A clone is a complete copy of the repository. You can create a clone of a Mercurial repo using the hg clone command, specifying the location of the Mercurial repository you would like to clone. Here's some examples:

You can clone a repo that is shared by someone by specifying the URL:

hg clone turing-repo-clone

You can clone a repo that is located locally if you want. For example, let's make a local clone of the repo we just cloned:

hg clone turing-repo-clone local-clone

You can also clone a repo that is available in your SSH home directory. For example, suppose you have a repository located in /home/user/test-repo. You can clone it via:

hg clone ssh:// test-repo-clone

Making Changes

Changes you make to your local copy of the repository are similar in syntax to working with Subversion. For example, you can make changes to your local repo using a process like this:

cd turing-repo-clone
## make some changes here ##
hg status
hg diff
hg commit

The status and diff commands let you see what's changed in your repository.

The commit command creates a changeset out of the collection of changes, and produces a new revision number. It is important to note the relationship between changesets and the terminology used in Mercurial: Each changeset has 0, 1, or 2 parent changesets. If it has 0 parents, then the changeset is called the root changeset of the repository. If the changeset has 2 parent changesets, it was created as the result of merging two changesets together. Changesets with no children are called heads, and the most recently changed head is called the tip.

Like Subversion, you can can revert and rollback within your local repo too:

hg revert
hg rollback

Sharing Your Changes

There are only three commands that communicate with other servers: push, pull, and clone. The clone command is introduced above.

The pull command will pull changes from another repo. Pull doesn't change your working directory, it just grabs the changesets. To actually apply the changes to your working dir, you must use the update command.

For example, the following pulls changes from turing-repo-updates into turing-repo-clone, then it attempts to apply the changes to the current dir:

cd turing-repo-clone
hg pull ../turing-repo-updates
hg update

If you are sharing a repository on the server, you can also push your changesets to the server. First, make sure all your changesets are applied (i.e you committed), Then push away!

hg push

List of Resource Pages in MASC
Computer Science @ George Mason University