如何在协作时管理配置文件? [英] How to manage configuration files when collaborating?

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

问题描述

我正在用一些简单的变量在页面顶部写一个简短的脚本。我想和一位朋友一起工作,但我们不确定如何管理每次拉我们其中一人后需要更改的变量,为垃圾状态添加不必要的垃圾。我想过为我们每个人创建不同的命名分支,然后主人将只设置示例用户名,但似乎很难做所有额外的工作合并。我们可以将这些变量作为选项传递给脚本,但这不是期望的,也不会将它分离到另一个单独的配置文件中。拥有类似.gitignore的东西真是太好了,但只能忽略文件中的几行。



这怎么能够被优雅地管理?这个问题通常如何管理?

解决方案

您不能轻易忽略对文件特定行的更改,我害怕,所以你可能坚持拥有一个单独的配置文件。下面我列出了处理这个问题的两种典型方法,以及一个稍微异乎寻常的方法:

在git中有一个示例配置文件



在这里,你会在git中保存一个文件 config.sample 作为例子,但是应用程序实际上会使用文件 config ,它位于 .gitignore 中。除非存在 config ,否则应用程序会产生一个错误。将新的配置变量添加到您的个人 config 文件中时,必须记住更改示例文件中的值。在这种情况下,让应用程序检查所有必需的配置变量是否已真正设置也是一个好主意,以防某些人忘记更改其 config 文件后更改样本。

在git中有一个默认值的文件

您保留一个文件 git中的config.defaults ,它尽可能具有合理的默认配置值。您的应用程序首先从 config.defaults ,然后从 config (它位于中)进行配置。 gitignore )可能会覆盖任何默认值。通过这种方法,通常你不会让 config> 不存在错误,所以应用程序可以为那些没有打算创建的人 config



使用带有--assume-unchanged

的单个配置文件

第三种可能性,在这种情况下,我个人不建议这样做,那就是拥有一个在git中提交的配置文件,但要使用 git update-index - -assume-unchanged< FILE> ,告诉git忽略对它的更改。 (这在这篇有用的博客文章。)这就意味着你的配置文件的本地修改不会被提交到 git commit -a 或者显示在 git status code>。


I'm writing a short script with a few simple variables at the top of the page. I want to work on them with a friend, but we aren't sure how to manage the variables needing to be changed after pulling each time for one of us, adding unnecessary junk to git status. I thought about just creating different named branches for each of us, and then the master will just have example usernames set, but it seems silly to have to do all that extra work merging. We could have the variables passed to the script as options, but that isn't desired, nor is separating it out to another separate configuration file. It would be great to have something like a .gitignore but for only ignore a few lines in a file.

How can this be elegantly managed? How is this problem usually managed?

解决方案

You can't easily just ignore changes to particular lines of a file, I'm afraid, so you're probably stuck with having a separate configuration file. Below I've listed two typical ways of dealing with this, and one slightly more exotic one:

Have a sample configuration file in git

Here, you would keep a file config.sample in git as an example, but the application would actually use the values in a file config which is in .gitignore. The application would then produce an error unless config is present. You have to remember to change values in the sample file when you add new configuration variables to your personal config file. In this case it's also a good idea to have your application check that all the required configuration variables are actually set, in case someone has forgotten to update their config file after changes to the sample.

Have a file of default values in git

You keep a file config.defaults in git, which has sensible default configuration values as far as possible. Your application first sources configuration from config.defaults and then from config (which is in .gitignore) to possibly override any of the default values. With this method, typically you wouldn't make it an error for config not to exist, so the application can work out of the box for people who haven't bothered to create config.

Using a single configuration file with --assume-unchanged

A third possibility, which I wouldn't recommend in this case, personally, would be to have a single configuration file which is committed in git, but to use git update-index --assume-unchanged <FILE>, to tell git to ignore changes to it. (This is described further in this useful blog post.) That means that your local changes to the configuration file won't be committed with git commit -a or show up in git status.

这篇关于如何在协作时管理配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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