开发者

How do I configure Mercurial to not commit specific config files?

My team is switching to Mercurial. Our projects all have a config file (web.config or app.config, and a few bat files as well - we are a C# shop). These files need to be part of the repository. When a developer clones the repository, local changes are needed to their config files to get them working. For example, a project's config file may need a connection string to the developer's database, or other environment-specific info. We don't want these changes ending up in the repository. And from time to time we do make changes to these configs that do need to get into the repository and distributed to the team and eventually the customer.

What is the easiest way for us to configure or use Mercurial so that these files are not getting committed by accident? I would like to be forced to make an explicit commit of such files, yet merges from the repo would automatically come down in updates.

This has to be a problem someone else has faced, but as Mercurial newbies we are all at a loss for the best solution.

Edit开发者_运维知识库:

A similar question that may share some common solutions, but is not the same as this question, can be found at: Conditional Mercurial Ignore File

I am including this in case that other question might provide the answer you are looking for.


The typical way to handle this is to store templates for the configuration files in your repositor, and add the actual configuration files to the ignore list in Mercurial.

This way, you have pristine, unmodified, copies of each configuration files available at all times, even for new developers who clone from scratch, but in order to make the configuration files usable, you need to make a local copy of it to the actual configuration file name, and modify the file. You could also use compare/merge programs, such as Beyond Compare, to compare a new version of the template file with your local copy of an older version, to see what changed, and add in the missing bits.

If you need to hard prevent committing the actual configuration files, you need a pre-commit or pre-push hook that does this.


In your .hg/hgrc file do this:

[defaults]
commit = -X Projectname/web.config

(assuming "ProjectName" is the project subdir)


Edit:

Also, if you're using Tortoise HG - add this as well:

[tortoisehg]
ciexclude = Projectname/Web.config,Projectname/App_Data/DBFile.mdf

(by the way mind the FORWARD slash in folder-path! Even on Windows!)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜