git 如何从 Github 隐藏 .env 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30696930/
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 11:05:51  来源:igfitidea点击:

How to hide .env file from Github

gitgitignore

提问by hidace

I'm using dotenv for my rails project to store API keys. I have the dotenv gem in my gemfile, created a .env in the root of my app and have my API keys listed in there. However, when I push up to github, I notice that the .env file is still there. Am I missing a step? How can I hide the .env file from being uploaded to github.

我正在为我的 rails 项目使用 dotenv 来存储 API 密钥。我的 gemfile 中有 dotenv gem,在我的应用程序的根目录中创建了一个 .env 并在其中列出了我的 API 密钥。但是,当我推送到 github 时,我注意到 .env 文件仍然存在。我错过了一步吗?如何隐藏 .env 文件被上传到 github。

Thank you!

谢谢!

回答by searsaw

Create a file called .gitignorein the root directory of your project (it's possible one is already there) and add .envon its own line in the file.

创建一个.gitignore在项目根目录中调用的文件(一个文件可能已经存在)并.env在文件中单独添加一行。

Also, if you have already added it to your repository, then you will have to add the file to .gitignoreas stated above and then clear Git's cache. You can find information on that in the following answer on StackOverflow.

此外,如果您已经将它添加到您的存储库中,那么您必须将文件添加到.gitignore如上所述,然后清除 Git 的缓存。您可以在 StackOverflow 的以下答案中找到相关信息。

回答by Andy Waite

You can exclude files from the repo with a .gitignore file: http://git-scm.com/docs/gitignore.

您可以使用 .gitignore 文件从 repo 中排除文件:http: //git-scm.com/docs/gitignore