在存储库中管理项目配置文件 [英] Managing project config files in repository

查看:111
本文介绍了在存储库中管理项目配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在git repo中管理配置文件有一些疑问.

I have some questions about managing config files in git repo.

问题1::假设我们在master中有一个.env,看起来像这样(变量刚刚声明但未定义!):

Question 1: Suppose we have .env in master that looks like this (variables just declared but not defined!):

XXX_CLIENT_ID=
XXX_SECRET=

然后有人拉主服务器,创建本地分支,更改.env,进行一些提交,然后合并到主服务器.在合并过程中,如何在.env文件中更改master分支?是git update-index --assume-unchanged解决了这个问题,还是我们可以更好地解决它?

Then someone pull master, create local branch, change .env, do some commits and then wants merge to master. How can master branch omits changing in .env file during merge? Is git update-index --assume-unchanged solves this or may be we can handle it better?

问题2:好,让我们看一下我们想要在团队中共享配置的情况,例如.dev.env.像master中的 Question 1 中一​​样,我们有类似.env的文件,但没有值,但是我们希望在团队中共享它,并且它应该是公开的,因为master仍是公开的.看来git-secret可以完成这项工作,但我想听听您今天使用什么来解决此问题.

Question 2: OK, let's look situation when we want share config in our team, for example .dev.env. Like in Question 1 in master we have file similar like .env without values but we want share it in team and it should be secret for public because master still public. It looks like git-secret do this job but I want hear what are you using today for solving this problem.

您如何在团队中管理它的任何好主意或最佳做法?

Any good idea or best practices how you manage it in your team?

推荐答案

对于问题1: 好的做法是将代码和配置分开.即,在保存您的代码的存储库中,您有一个.env.sample文件,该文件指定应用程序期望设置的配置变量(可能具有默认值). 然后,从本地主机克隆或分支的人员可以在添加到.gitignore.env文件中指定其属性值,因此不会影响git树.当开发人员在本地对应用程序进行测试时,它将使用.env中的配置,该配置特定于开发人员的环境.

For question 1: A good practice is to separate code and configuration. I.e in the repository that holds your code you have a .env.sample file that specifies what config variables the application expects to be set (possibly with default values). People cloning or branching out from master locally can then specify their property values in a .env file that is added to .gitignore and thus not impacting the git tree. When the application is tested locally by the developer it uses the configuration in the .env, which is specific to the environment of the developer.

这样,您可以将.env.sample文件保留在master中,以向公众表明需要什么配置,但是克隆者需要为其本地环境指定自己的.env

This way you can keep a .env.sample file in master indicating to the public what config is needed, but cloners need to specify their own .env for their local environment

开发人员仅在添加/删除配置后才编辑.env.sample文件(这是需要合并回母版的信息)

A developer only edits the .env.sample file if config is added/removed (which is information that needs to be merged back to master)

这篇关于在存储库中管理项目配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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