![](/img/trans.png)
[英]How can I reset a file ignore by git (not configured in .gitignore)?
[英]How can I ignore the .env file in git?
我在 my.env 文件中进行了更改,然后在终端git status
中写入:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .env
我希望 git 忽略 .env 文件中的更改,所以我在.gitignore 中添加了这一行:
/.env
现在当我写git status
我得到结果:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .env
modified: .gitignore
我现在能做什么? 为什么 gitignore 不被忽略?
git rm --cached.env
(这将使 to.gitignore 能够运行)的问题在于,一旦提交并推送,每个人都会在下一次git pull
时丢失文件。
如果您需要本地.env
设置(不应该是 Git 存储库的一部分),您可以:
#include
指令,这将允许您包含第二个 file.env.local (您可以安全地添加到您的.gitignore
).env.tpl
(模板文件),同时忽略.env
本身(因此使用git rm --cached.env
,但使用 git 添加.env.tpl
) 内容过滤器驱动程序背后的想法是在git checkout
/ git switch
.env
文件时自动生成,基于.env.tpl
模板文件和本地(和被忽略的) .env.values
值文件。
请参阅“ Github 私人仓库 - 管理不同环境的包”作为这种方法的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.