使用 git 处理配置文件的最佳方法是什么?

发布于 2024-07-12 22:29:50 字数 279 浏览 4 评论 0原文

假设我的应用程序有一个纯文本的配置文件。 它们包含一些在我的开发环境中测试应用程序所需的敏感信息。 我使用不同的操作系统来访问和处理我的项目(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转身以后 2024-07-19 22:29:50

在 Django 世界中,您可以使用一个约定 - 有一个标准的 settings.py 文件,它会在末尾导入一个 local_settings 模块(如果有可用的模块)。

将所有秘密内容放在 local_settings.py 文件中,并将其添加到 .gitignore 中,这样它就不会进入存储库。 这样,人们就会知道他们可以将自己的设置添加到 local_settings 中。

例如,

settings.py

DATABASE_USERNAME = 'your username here'
DATABASE_PASSWORD = 'your password here'

local_settings.py

DATABASE_USERNAME = 'my top secret username'
DATABASE_PASSWORD = 'my top secret password'

最好的部分是,您在 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 a local_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 to local_settings.

For example,

settings.py:

DATABASE_USERNAME = 'your username here'
DATABASE_PASSWORD = 'your password here'

local_settings.py:

DATABASE_USERNAME = 'my top secret username'
DATABASE_PASSWORD = 'my top secret password'

The best part is that whatever you've defined in settings.py will get overridden by the same name in local_settings.py.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文