如何实用地版本控制配置文件? [英] How to version control config files pragmatically?

查看:27
本文介绍了如何实用地版本控制配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个包含敏感密码的配置文件.我想对整个项目进行版本控制,包括配置文件,但我不想分享我的密码.
如果这个配置文件:

Suppose we have a config file with sensitive passwords. I'd like to version control the whole project, including the config file as well, but I don't want to share my passwords.
That could be good, if this config file:

database_password=secret
foo=bar

变成

database_password=*
foo=bar

其他vcs用户也可以自行设置密码.忽略文件不是一个好方法,如果配置文件发生变化,开发人员应该注意.

and the other users of the vcs could also set up the password on they own. To ignoring the file isn't a good approach, the developers should be aware, if the config file changes.

本地版本:

database_password=own_secret
foo=bar

vcs 中的配置文件:

config file in vcs:

database_password=*
foo=bar

然后突然,配置文件发生了变化:

Then suddenly, the config file changes:

database_password=*
foo=bar
baz=foo

本地版本将成为每个开发人员的:

And the local version would become for each developer:

database_password=own_secret
foo=bar
baz=foo

这是我的解决方案.我怎样才能实现这种行为?你如何存储你的配置文件?有没有办法做到这一点,或者我应该破解什么?

This is my solution. How could I achieve this behaviour? How do you store your config files? Is there a way to do that, or should I hack something?

推荐答案

您可以在版本控制中放置一个模板或默认文件,而不是版本控制实际的配置文件,以及一个要求数据库信息和凭据的脚本生成真正的配置文件,该文件将从(即被忽略)版本控制中排除.在结帐时,开发人员可以运行此脚本以获得工作环境.该脚本也可以作为您的应用程序使用的任何安装过程的一部分被调用.

Instead of version-controlling the actual configuration file, you could put a template or defaults file in version control, and a script that would ask for DB information and credential to generate the real config file, which would be excluded from (i.e. ignored by) version control. On checkout, developers could run this script to get a working environment. This script could also be invoked as part of any installation process that your application uses.

另外查看我对类似问题的回答.

这篇关于如何实用地版本控制配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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