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?
Once you decide that a file no longer belongs in your repository, use the hg remove command. This deletes the file, and tells Mercurial to stop tracking it (which will occur at the next commit). A removed file is represented in the output of hg status with a “ R ”.
If you see the help for hg rm --help : hg remove [OPTION]... FILE... Schedule the indicated files for removal from the current branch. This command schedules the files to be removed at the next commit.
hgignore file sits in the working directory, next to the . hg folder. It is a file versioned as any other versioned file in the working directory, which is used to hold the content of the ignore patterns that are used for any command operating on the working directory.
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'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With