laravel git ignore .env 文件不起作用

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

git ignore .env files not working

gitlaravellaravel-5.2gitlab

提问by Matt

I have a laravel project. In the root directory are these 4 files:

我有一个 Laravel 项目。根目录下有这4个文件:

.env .env.example .env.local .env.staging

.env .env.example .env.local .env.staging

I have a .gitignore file, and I'm listing these 4 files in the .gitignore, one after another, like this

我有一个 .gitignore 文件,我将这 4 个文件一个接一个地列在 .gitignore 中,就像这样

.env
.env.example
.env.local
.env.staging

My git repository does not contain .env or .env.example, but it DOES contain .env.local and .env.staging. I've tried everything I can think of, but it keeps syncing these 2 files with Gitlab.

我的 git 存储库不包含 .env 或 .env.example,但它确实包含 .env.local 和 .env.staging。我已经尝试了所有我能想到的方法,但它一直将这 2 个文件与 Gitlab 同步。

Any ideas what could be causing this?

任何想法可能导致这种情况?

Thanks for your help!

谢谢你的帮助!

回答by Bryce Drew

Use git rm:

使用git rm

If you have already added the files to be tracked, you need to remove them from tracking:

如果您已经添加了要跟踪的文件,则需要将它们从跟踪中删除:

git rm env.local --cached
git rm env.staging --cached
git commit -m "Stopped tracking env.local, and env.staging"

Now you should be able to clone your branch without those files being tracked.

现在您应该能够在不跟踪这些文件的情况下克隆您的分支。

Note:Keep in mind that the contents of those files are in your history, and if they did contain sensitive data, then you need to completely removethat from history before putting it out there.

注意:请记住,这些文件的内容在您的历史记录中,如果它们确实包含敏感数据,那么您需要在将其从历史记录中完全删除之前将其删除。

回答by Chirag Ingde

Simply Run This Command.

只需运行此命令。

git rm .env --cached
git commit -m "Stopped tracking .env File"

In laravel there are .env file include for connecting database. So for that you must remove .env file from cached.

在 laravel 中有 .env 文件包含用于连接数据库。因此,您必须从缓存中删除 .env 文件。