Untrack files without removing from remote repository

163 views Asked by At

In our company, we just started using Mercurial and we are facing the following problem:

We have some files in the remote repository that are changed by each developer to add some local configuration but these files must never be changed in the remote repository.

Is there a way to tell Mercurial to stop tracking those files locally without making any change to the file on the remote repository?

We tried with hg forget <file> but as I understand, this will remove the file from the remote repository.

We also tried adding those files to .hgignore file, but somehow the files are not really being ignored, I guess Mercurial does this because the files are already being tracked.

So far, we are just ignoring the files when we perform a commit and we use shelve to maintain and restore our local changes after an Update, but it's starting to be a really tedious task.

Thanks in advance for any help.

EDIT: Although it didn't completely fix what we wanted to, accepted answer is the best approach. Our problem is probably a result of a bad design.

3

There are 3 answers

1
Mark Tolonen On BEST ANSWER

If the file you want unchanged is, for example, config.cfg, check in a config_template.cfg, forget config.cfg if it is already tracked, and add config.cfg to the ignore list. Then, a build rule can create config.cfg from the template if it does not already exist.

A user will then have a starting config.cfg that they can customize without checking it in.

1
Christophe Muller On

You could use the configuration [defaults] section to add some "--exclude" options to usual commands (see my answer to Mercurial hg ignore does not work properly ) for more details.

But.. be careful that it is dangerous to silently ignore modifications to files and also that this [defaults] section has been marked as deprecated (it is still present in 2.9.2).

0
planetmaker On

IMHO it's a wrong approach to have a file in the repository which every person needs changed anyway - it's an indication that you do not want to have it tracked at all.

Change the file to config.sample, and have your programme create a default config upon first start (thus when there's no existing config file) and have every developer use the config file as s/he needs.

And I see Mark Tolnen's answer only now :)