提交机器特定的配置文件 [英] Committing Machine Specific Configuration Files

查看:144
本文介绍了提交机器特定的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开发的一个常见的情况是,代码库将有几个配置文件,需要机器特定的设置。这些文件将被检入Git,其他开发人员总是会不小心检查他们并破坏别人的配置。



一个简单的解决方案是只是不检查他们进入Git,甚至为它们额外添加一个.gitignore条目。然而,我发现在文件中有一些明智的默认值,开发人员可以根据自己的需要修改它。更多的优雅。



有一个优雅的方式Git玩这样的文件很好?我想能够修改特定于机器的配置文件,然后能够运行git commit -a而不检查该文件。

解决方案

让程序为其设置读取一对配置文件。首先,它应该读取将包括在存储库中的 config.defaults 文件。然后,它应该读取应该在 .gitignore

$ b $中列出的 config.local b

使用此安排,新设置将显示在默认文件中,并在更新后立即生效。



作为一个变体,你可以只有一个 config 文件,它在版本控制中运行,并且它做类似于 include config.local 以引入特定于计算机的值。这将在代码中引入一个更通用的机制(与策略),从而实现更复杂的配置(如果这对您的应用程序是可取的)。在许多大型开源软件中看到的流行扩展是 include conf.d ,它从目录中的所有文件读取配置。 p>

另外请参阅我的回答一个类似的问题。


A common scenario when I develop is that the codebase will have several config files which require machine specific settings. These files will be checked into Git and other developers will always accidentally check them back in and break someone else's configuration.

A simple solution to this would be to just not check them in to Git, or even to additionally add a .gitignore entry for them. However, I find that it is much more elegant to have some sensible defaults in the file which the developer can modify to suit his needs.

Is there an elegant way to make Git play nicely with such files? I would like to be able to modify a machine-specific configuration file and then be able to run "git commit -a" without checking that file in.

解决方案

Have your program read a pair of configuration files for its settings. First, it should read a config.defaults file that would be included in the repository. Then, it should read a config.local file that should be listed in .gitignore

With this arrangement, new settings appear in the defaults file and take effect as soon as it's updated. They will only vary on particular systems if they're overridden.

As a variation on this, you could have just a general config file that you ship in version control, and have it do something like include config.local to bring in the machine-specific values. This introduces a more general mechanism (versus policy) in you code, and consequently enables more complicated configurations (if that's desirable for your application). The popular extension from this, seen in many large-scale open-source software, is to include conf.d, which reads configuration from all the files in a directory.

Also see my answer to a similar question.

这篇关于提交机器特定的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆