git 在 Rails 项目中忽略 .gitignore config/database.yml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8494783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:15:09  来源:igfitidea点击:

Ignoring .gitignore config/database.yml in a rails project

ruby-on-railsgitconfiguration

提问by Mikey Hogarth

When working on rails project (I'm still in the "beginner" phase of learning at the moment by the way) the file config/database.yml seems to be the one where things like database passwords etc. go. However, nobody seems to recommend putting it in the .gitignore file - why?

在处理 rails 项目时(顺便说一下,我目前仍处于学习的“初学者”阶段)文件 config/database.yml 似乎是数据库密码等内容所在的文件。但是,似乎没有人建议将它放在 .gitignore 文件中 - 为什么?

Surely I would need to exclude this or my sensitive database configuration details would end up being public knowledge if I pushed to github.

当然,我需要排除这个,否则如果我推送到 github,我的敏感数据库配置细节最终会成为公共知识。

采纳答案by Dan

database.ymlis the proper place for configuring your database credentials. Normally you'd commit database.ymlwhile only configured with your development and testing environments.

database.yml是配置数据库凭据的正确位置。通常,您database.yml只会在配置开发和测试环境时提交。

I don't have passwords on my local Postgres and MySQL instances so I can safely commit database.yml. If you want to ignore it, just add database.ymlline to the end of your .gitignorefile. You'll need to make sure it's cleaned up and committed before ignoring it. Then you can make your changes safely.

我的本地 Postgres 和 MySQL 实例上没有密码,因此我可以安全地提交database.yml. 如果您想忽略它,只需database.yml.gitignore文件末尾添加一行即可。在忽略它之前,您需要确保它已被清理和提交。然后您可以安全地进行更改。

Once you deploy to production you would symlink it in from a copy already stored on that server with the sensitive credentials.

部署到生产环境后,您可以使用敏感凭据从已存储在该服务器上的副本中对其进行符号链接。

回答by daniel

You should'nt have passwords in your database.yml....I don't. Why do you have passwords? If you deploy to heroku read: http://devcenter.heroku.com/articles/config-vars

你的 database.yml 中不应该有密码......我没有。为什么你有密码?如果您部署到 heroku,请阅读:http: //devcenter.heroku.com/articles/config-vars

If you still want to ignore it add:

如果您仍然想忽略它,请添加:

echo "database.yml" >> .gitignore