开发者

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

开发者 https://www.devze.com 2023-03-18 14:35 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Mercurial: How to ignore changes to a tracked file
This question already has answers here: Closed 11 years ago.

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 th开发者_JS百科e repository itself?


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.


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.


You can just exclude the file in future commits.

This can be a bother if you use hg from the command line as you would have to specify manually which files you want to commit but if you use something like tortoisehg you can just uncheck the config file in the commit form and it's changes won't go in to the changeset.

0

精彩评论

暂无评论...
验证码 换一张
取 消