Abel
Abel

Reputation: 57159

How to freeze a file for changes but leave it in the repository using Mercurial

Quite often I have a situation like the following:

I would like to keep a version history on these files, but they will only occasionally be updated. It is annoying if every time you do a commit or merge or update you have to remember that you do not want to commit your locally changed password.

How can I freeze a file in the repository (and conversely, for the occasional legitimate update, unfreeze it) so that it does not appear in the commit list, but does appear as versioned in the repository and everyone can share a base copy?

Upvotes: 0

Views: 149

Answers (2)

Ry4an Brase
Ry4an Brase

Reputation: 78330

This question gets asked a lot, and the answer is always the same: there's no good way to do what you want. A file that's tracked is tracked for all changes.

The setup everyone settles on is committing a configurationfile.example to the repo where changes everyone needs are shared, and add configurationfile to your ignore. If you're savvy you then have your launch script copy configurationfile.example to configuration location if it doesn't already exists. If your configuration format is flexible enough to support an include (most are these days) you have you configurationfile committed and have it do an include of a non-tracked (ignored) configurationfile.local where people override things. This is how everyone does it in both git and Mercurial.

Upvotes: 3

Lazy Badger
Lazy Badger

Reputation: 97282

-X option for commit, none (easy) for merge

-X --exclude PATTERN [+] exclude names matching the given patterns

i.e most times you commit hg ci -X FILENAME, sometimes - pure hg ci. You can define hg ci -X FILENAME as new alias and use two different commands for different commits

In case of merges you can try to define for config-file special merge-tool (provably internal:local or internal:fail)

Anyway, you selected wrong and error-prone method of storing local configs as shared common files. (Viable) alternatives may include (in order to name a few)

  • Config.TEMPLATE in repository and modified for local needs hgignore'd Config
  • LocalBranch, in which you store code with location-specific changes
  • MQ extension (somehow related to 1-st solution) - repository stored "vanilla" config, all local-only changes placed in MQ-patch

Upvotes: 2

Related Questions