Is there an ignore-on-commit option in mercurial?

Nick Randell picture Nick Randell · May 19, 2009 · Viewed 13.9k times · Source

Is there any way to ignore changes to some files on a commit with mercurial?

I've got a specific situation where we have a default oracle tnsnames.ora file that points to 127.0.0.1, but some developers will modify it to point to other systems, but we don't want to change the default file.

In subversion, I've simple added this to the ignore-on-commit changelist. Is there a way of doing this in mercurial?

Answer

Giorgos Keramidas picture Giorgos Keramidas · May 22, 2009

If the files you want to omit from the "hg commit" command are already "tracked", you should use the -X option. The pattern passed to -X is pretty flexible, making it possible to run for example:

% hg stat
A etc/foo.conf
M src/bar.c
M lib/libbar/loader.c
% hg commit -X '**.conf'

to avoid committing any file with a ".conf" extension, regardless of how deep in the source tree it lives. In the workspace shown above this would commit "src/bar.c" and "lib/libbar/loader.c" but not "etc/foo.conf".

To exclude multiple patterns of filenames, use multiple -X options, i.e.:

% hg commit -X '**.conf' -X '**.sh'