Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore future changes to a file in Mercurial, but still track it [duplicate]

Tags:

mercurial

Possible Duplicate:
Mercurial: How to ignore changes to a tracked file

I have a file in a Mercurial repository that I want to have stand as an example configuration file, but while I'm developing it I want to make specific changes to it I don't want tracked, like a database password. I tried adding that file to .hgignore, but Mercurial still notices modifications.

Can I have a file "tracked" in a Mercurial repository, yet ignore future local changes to that file without removing it from the repository itself?

like image 344
Rich Avatar asked Jul 07 '11 17:07

Rich


2 Answers

I don't think this capability exists (love to see someone else's answer with an option though :) ). The alternative I've used is to check a file into source control named "config.template" (as an example). The app actually uses a file named "config", which I then create by copying the template file. Then make sure that the "config" file is excluded in the .hgignore file so you don't accidentally check in sometime.

like image 112
Chris Shaffer Avatar answered Oct 05 '22 14:10

Chris Shaffer


No, there is no support built into Mercurial to automatically handle this, well... not in the way you're asking about.

There's two states of a file:

  • Tracked
  • Untracked

The only thing the .hgignore file does is to help with all the commands that just looks at all the untracked files and add them to the repository (ie. add them for tracking.) Once a file is being tracked, it will always be tracked.

The rest is left to manual handling, which means that if you track a file, but don't want to commit changes to it, you will have to uncheck, ignore, or otherwise make sure the commit command doesn't commit it, every time you commit.

The preferred way to handle this is instead to commit a template. Then, if possible, you add a step to your build process that checks if the actual configuration file is present, and if not, make a copy from the template. This actual configuration file you ensure is not tracked, and added to the .hgignore file.

This way, you can change the actual configuration file, but unless you specifically add it to the repository, it will not be tracked automatically, and there's nothing to do during commit.

like image 43
Lasse V. Karlsen Avatar answered Oct 05 '22 13:10

Lasse V. Karlsen