How to show relative path in hg status

By default, hg status shows modified files with path from the root of the working directory. Most of the time, I would like it show the paths relative to my current directory.

There is no --relative option and due to the few people who need this feature, Mercurial developers have said that such a flag will not be added.

However, applying an empty regular expression or pattern to the status command gets the job done:

$ hg status re:
$ hg status ""

Tried with: Mercurial 3.4 and Ubuntu 15.10

How to ignore files and directories in SVN

It is easy to ignore files and directories in Git or Mercurial. Ignore files can be maintained at both the user and repository levels. Git or Mercurial automatically ignore the files and directories that match the patterns listed in these ignore files.

Being a version control system from an older era, Subversion does not have this simple method of ignore.

  • In SVN, ignoring a file or directory is a property that can be set at a specific directory in a repository.

For example, to ignore build subdirectory and *.tmp files:

$ svn propset svn:ignore build .
$ svn propset svn:ignore *.tmp .

Note that both these commands set ignore properties for the current directory .

  • To set an ignore property recursively to all subdirectories in a repository, go to the repository root directory and issue this:
$ svn propset svn:ignore -R *.tmp .
  • Thankfully, you can use an ignore file containing ignore patterns, one per line, as input:
$ svn propset svn:ignore -R -F ~/.svnignore .

Note the difference with Git or Mercurial. You have to manually set this ignore property on every directory. The ignore file we created is for our convenience. If you create a new subdirectory anywhere in this repository, the property needs to be applied again on it.

  • Remember to commit after setting the ignore property.

Tried with: Subversion 1.8.8 and Ubuntu 14.04

Record extension for Mercurial

Record is an important extension for Mercurial and it ships along with it. It provides the record command, using which you can pick and choose which changes and modified files you want to commit. It feeds you the changes and modified files in an interactive format, so you do not have to type out long paths or other specifications.

You can specify which of the modified files you want to commit to the commit command, but typing out the file paths like that is cumbersome. Also, it does not allow you to pick and choose changes inside a file. I feel that the record command is better for this use case.

To enable the Record extension, add these lines to your hgrc:

record =

Using it is as simple as:

$ hg record

For each change or file it shows, you can provide one of these inputs:

y - record this change
n - skip this change

s - skip remaining changes to this file
f - record remaining changes to this file

d - done, skip remaining changes and files
a - record all changes to all remaining files
q - quit, recording no changes

? - display help

Tried with: Mercurial 2.8.2 and Ubuntu 14.04

How to use hgwatchman extension for Mercurial

hg status command can be very slow on a repository with thousands of files. This is because it has to explicitly check the status of every file. A great method to speed it up is the hgwatchman extension for Mercurial. It uses the Watchman tool which relies on the inotify mechanism of the Linux kernel to be notified directly of only the changes that occurred to the files in a directory. There are no packages of hgwatchman and Watchman for Ubuntu, so we need to build them from source. But it is pretty easy to do:

  • Install the Watchman tool as described here.

  • Download the hgwatchman source code:

$ hg clone
  • Build the code:
$ cd hgwatchman
$ make local

If you forget this step, everything seems to be fine until you start seeing this error:

$ hg status
abort: No module named bser! is a module that is built by this step.

  • Add these lines to your hgrc:
hgwatchman = /path/to/hgwatchman/hgwatchman

mode = on
  • That is it! You should see a nice improvement in the performance of hg status after using hgwatchman.

Tried with: Watchman 3.0.0, Mercurial. 2.8.3 and Ubuntu 14.04

How to use inotify extension for Mercurial

hg status is the slowest command in Mercurial and can take several seconds on repositories with thousands of files. This is because it needs to check every single file and directory in your repository to see if it has changed. One method to speed up this command is to use the inotify extension for Mercurial.

Note: This extension is reported to be buggy and using the alternate hgwatchman extension is recommended.
Note: This extension only works in Mercurial 2.x. It has been explicitly disabled in Mercurial 3.x and will not work.

This extension ships with the mercurial-common package and so it will already be installed on your system if you have Mercurial. It relies on the inotify subsystem of the Linux kernel and any kernel later than 2.6.13 will have it. It uses the filesystem to watch for changes and reports these to applications. Using this Mercurial can check the status of gigantic repositories quickly.

To enable this extension, just add these lines to your hgrc:

inotify =

That is it! I noticed a speedup on a large repository with 500K files, but it was not as much as I wanted.

Tried with: Mercurial 2.8.2, Linux 3.13.0 and Ubuntu 14.04

HgList extension for Mercurial

When I am at the shell inside a Mercurial repository, I sometimes want to list only those files that are under version control and some details about them. Something like the ls command, but for Mercurial. That is exactly what the HgList extension for Mercurial sets out to do.

It can be installed from PyPI easily:

$ sudo pip install hglist

To enable it, add this line to your global .hgrc:

hglist =

It can be used at any directory inside any Mercurial repository:

$ hg list
$ hg ls
$ hg ls -l -H

Tried with: HgList 0.3, Mercurial 2.8.2 and Ubuntu 14.04

How to use Quick Diff in Eclipse

Added, modified and deleted lines marked by Quick Diff in Eclipse editor.
Added, modified and deleted lines marked by Quick Diff in Eclipse editor.

Eclipse has support for version control systems like Git, SVN and CVS. Support for Mercurial can be enabled by using the MercurialEclipse plugin. When viewing files in version control, it is common practice to quickly see which of the lines are uncommitted compared to the current head (or parent) revision. This information can be viewed in Eclipse by using its Quick Diff feature. This is easy to do:

  1. Go to Window -> Preferences -> General -> Editors -> Text Editors -> Quick Diff. This is the dialog from where it can be configured.

  2. Turn on Quick Diff, by enabling the option Enable quick diff.

  3. Choose the version control system for which Quick Diff is needed from the dropdown Use this reference source. Git, SVN and CVS should be present here. Mercurial appears if the MercurialEclipse plugin is installed.

  4. The overview ruler is the ruler to the right of the scrollbar in the editor. If you would like to see the uncommitted lines to be marked on it, enable the option Show differences in overview ruler.

  5. Choose Apply and OK. Close all editor windows and reopen the source file that you want in the editor.

You should be able to see the newly added, modified or deleted lines marked in colors in the left bar on which line numbers are usually displayed. The colors used are the ones set in the Quick Diff dialog (see above steps). You can also view these uncommitted locations marked along the overview ruler on the right.

Tried with: Eclipse Luna 4.4.1 and Ubuntu 14.04

How to use MercurialEclipse plugin

The MercurialEclipse plugin brings support for Mercurial to Eclipse.

  • To install it, go to Help -> Install New Software and add the URL:

  • I usually manage Mercurial from the shell. To enable Mercurial support for an existing project that is placed in a Mercurial repository is easy. Click on the project in Project Explorer, choose Team -> Share Project. Click on Mercurial and click Next. Choose Use existing repository in parent directory. Check if the path in Selected Repository is correct. Click Finish.

  • When Mercurial support is working, you can see that the directories and files shown in Project Explorer have icon overlays that indicate their modified or committed status.

  • Almost all the Mercurial operations can be accessed by clicking on the project or file in Project Explorer and choosing Team. Its a bit confusing that this is not named something appropriate like Mercurial or Hg or even version control.

  • To view the history log of the project, choose Team -> Show History. The History window is shown at the bottom of Eclipse. To enable viewing the graph of changes, click on the Show Parent History button in this window.

  • To view the uncommitted changes of a file as a side-by-side diff with its parent revision, click on the file and choose Compare With.

  • Other basic operations of this plugin are described in this page.

Tried with: MercurialEclipse 2.1.0, Eclipse Luna 4.4.1 and Ubuntu 14.04


Extensions like Hg-Prompt help print the version control status to the command prompt, as described here. But, it is written in Python and launching the Python interpreter on every command is too slow at the command prompt. That is the last place where you need things to be slow!

The solution for speed is always C/C++! VCPrompt is a tool that is written in C/C++ by Greg Ward that can be used to print status of version control in the shell prompt. It is extremely fast due to it being a binary. It can handle Mercurial, Git and Subversion repositories.

To install from PPA:

$ sudo add-apt-repository ppa:voronov84/andreyv
$ sudo apt-get update
$ sudo apt install vcprompt

To install it from source:

$ hg clone
$ cd vcprompt
$ autoconf
$ ./configure
$ make
$ sudo make install

To use vcprompt, specify the information you need in its format specifier:

$ vcprompt -f "%n:%r:%u%m"

It can be easily incorporated into a shell prompt, by grabbing its output.

Note: VCPrompt has a few missing features, including not being able to show details of Git submodule. There is another VCPrompt inspired by this one here which has these features. However, it is written in Python, which makes its choice moot.

Tried with: Ubuntu 14.04