使用 git 处理配置文件的最佳方法是什么?
假设我的应用程序有一个纯文本的配置文件。 它们包含一些在我的开发环境中测试应用程序所需的敏感信息。 我使用不同的操作系统来访问和处理我的项目(win、mac...)。
我不希望配置文件中的某些信息进入我的公共 git 存储库。 在最好的情况下,我希望用占位符替换敏感信息,并将配置文件上传到存储库以跟踪其结构。
你会如何解决这个问题?
钩子本身对我来说写起来不会有太大问题。 我更感兴趣的是如何将它们结合在一起,可能的目录结构等。我对 git 很陌生。
Say my application has a configuration files in plain-text. They contain some sensitive information which is required to test the application in my dev environment. I use different OSes to access and work on my projects (win, mac, ... ).
I do not wish some of the information in the configuration files to make it to my public git repository. In best case I want the sensitive information to be replaced with placeholders and have the configuration files uploaded to the repository to keep track of their structure.
How would you approach the problem?
The hook itself wouldn't be much of a problem for me to write. I'm more interested how to tie it all together, possible directory structure, etc. I'm quite new to git.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Django 世界中,您可以使用一个约定 - 有一个标准的
settings.py
文件,它会在末尾导入一个local_settings
模块(如果有可用的模块)。将所有秘密内容放在
local_settings.py
文件中,并将其添加到.gitignore
中,这样它就不会进入存储库。 这样,人们就会知道他们可以将自己的设置添加到local_settings
中。例如,
settings.py
:local_settings.py
:最好的部分是,您在
settings.py
中定义的任何内容都将被覆盖local_settings.py
中的名称相同。There's a convention followed in the Django world that you could use - there is a standard
settings.py
file that imports alocal_settings
module at the end if there is one available.Have all your secret stuff in that
local_settings.py
file and add it to.gitignore
so that it doesn't go to the repository. This way, people will know that they can add their own settings tolocal_settings
.For example,
settings.py
:local_settings.py
:The best part is that whatever you've defined in
settings.py
will get overridden by the same name inlocal_settings.py
.