I have a file with database settings in my project which I have set to some defaults. The file is tracked by Mercurial and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Mercurial to ignore new changes to this file?
I tried adding the file to the .hgignore
file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?
There is no truly automated process, but you can try (as in this SO question) the
-X
option onhg commit
:(other solutions might involve shelve or hq)
However, this is not the "right" solution. I would rather recommend versioning:
Typically you would check in a reference copy of the file and track it then have the developers make a copy of that for local development, you wouldn't really want developers editing the source controlled file for their own environments.
If your configuration system supports it, it's even easier if you can use an override file that simply override values in the reference copy (e.g. the database connection string). That way devs only have to keep a very minimal local set of override values.
If you always want to ignore the file, you can add the
-X
option as a default forcommit
to your.hg/hgrc
configuration file:We wrote an extension for this called exclude. It will automatically add the
-X
options on the commands that support them -- sohg status
andhg commit
wont see the modified file. It works by reading a.hgexclude
file from the root of your repository, just like the.hgignore
file. You add the files that you want to exclude there:The extension works quite well, but there is a known situation where it fails: merges and the commit that follows a merge (this is documented on the wiki). It would need to be improved so that it would save the modifications away to a temporary file and then restore them afterwards. Please get in contact if you need this feature.
You can try
hg forget
. For more details, see the official manual about the same command. It worked for me.I think, something like this is closer to a correct answer to the original question Mercurial: How to ignore changes to a tracked file, rather than the others suggesting a template, etc.
If you are using TortoiseHG, open the Settings for the repo, go to the Commit section (2nd icon down on the left) & add the file name(s) to the Auto Exclude list on the right (~ 3rd from the bottom in the list).
From https://tortoisehg.readthedocs.io/en/latest/settings.html#commit