40
votes

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?

4

4 Answers

52
votes

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'
22
votes

Traditionally, this is solved by not versioning the file itself, but by versioning a copy of it as a template for others to use.

So you would hg mv tnsnames.ora tnsnames.ora-template, then commit, then do a straight filesystem copy of tnsnames.ora-template to tnsnames.ora, and add tnsnames.ora to the .hgignore file.

Subsequent changes to the template will still get pushed out, but they won't actually change the working environment unless someone copies the template to the actual file.

1
votes

You could alias commit to something like 'hg commit -X excluded_file.ext' I've never used mercurial, so I'm just going by the man page here.

-2
votes

Look for .hgignore file in Mercurial's documentation.

Here is an example ignore file.

       # use glob syntax.
       syntax: glob

       *.elc
       *.pyc
       *~

       # switch to regexp syntax.
       syntax: regexp
       ^\.pc/