From Supernifty
Jump to: navigation, search

As with Bazaar, Mercurial is a distributed VCS, which means there isn't the headache of arranging a centralized repository.

There is a very usable plugin for Windows users which integrates with Explorer: TortoiseHg, which makes Hg much nicer to use with Windows.

If you're using Windows, after installing TortoiseHg, just right click and use the provided interface.

Otherwise, common commands:

Common Commands

Starting a repository

  • hg init - new repository
  • hg clone repository - copy repository to current directory
  • hg clone repository new repository - copy repository to a new location
  • hg add file - add a file to the repository
  • hg commit - commit changes to repository


  • hg log - show history
  • hg status - show changed files
  • hg diff - show changes to files
  • hg tip - what's the latest changeset?

Pulling from a repository

  • hg incoming repository - pull without changing
  • hg pull repository - pull in changes from repository into current repository
  • hg update - take changes from repository and applies to actual files

Pushing to a repository

  • hg outgoing repository - push without changing
  • hg push repository - push changes to repository

Merging repositories

  • hg pull other repository - get their changes
  • hg update - fails
  • hg merge - merges changes
  • hg commit - commits back to repository


  • hg tag tagname - add a tag to the current version
  • hg rename from to - rename a file
  • hg revert filename - undo changes to file
  • hg rollback - undo last commit or pull
  • hg serve - super fast way of sharing a repository


To host a mercurial repository

Assuming you have Python installed...

Install Mercurial

  • easy_install -U mercurial
  • If on a virtual server, you may need to install this in your home directory: easy_install –install-dir ~/lib/python/ -U mercurial

Install CGI script

Configure CGI script

  • edit index.cgi
  • if you are using your own version of python, set it in line 1
  • if necessary, add a path to the mercurial library:
import sys
sys.path.insert(0, "/path/to/mercurial")

Configure repositories

  • edit hgweb.config
reponame = /path/to/repo

If you don't already have a repository, make one with the command hg init, while in the directory /path/to/repo

Configure Access

  • htpasswd -c /path/to/htpasswd
  • Create file .htaccess
AuthUserFile /path/to/htpasswd
AuthGroupFile /dev/null
AuthName "Authentication Required"
AuthType Basic
Require valid-user

Configure repository access

  • In /path/to/repo/.hg, edit hgrc
  • Start the file with the line
  • To let anyone push:
allow_push = *
  • By default, https is required for pushes. To allow http:
push_ssl = false


  • Apache is fairly picky on permissions
  • Make sure it has correct access to .htaccess, htpasswd and the repository