Using .hgignore

If you’re tracking changes in your source code using Mercurial, you’ll probably find using an .hgignore file helpful.

The function of .hgignore, like its close cousin, .gitignore, is to to allow you to exclude certain files from being tracked by the source control system. Transient or “variable” files like logs, temporary files and user contributed images are top candidates for such treatment.

Fortunately the syntax for .hgignore follows already established conventions. For example, its regular expression method will be familar to those who work with regexes in perl, java and other languages. There are lots of helpful articles on the Internet on the topic, as you can see from this compilation.

Here’s an example from real life:

# Use glob syntax
syntax: glob
*.log

# Switch to regex syntax
syntax: regexp
storage/views/.+
public/.sass-cache/.+
public/img/profiles/A.+\.jpg
public/img/profiles/Z.+\.jpg
public/img/thumbnails/A.+\.jpg
public/img/thumbnails/Z.+\.jpg
public/img/temp/.+
This entry was posted in Development, System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).