英文:
How to ignore a file located in the same folder as .gitignore
问题
My .env file is located in the same folder as my .gitignore file.
Therefore, my .env file is not taken into account and is offered to me to be sent to git. How can I do?
How can i ignore my .env file ?
英文:
My .env file is located in the same folder as my .gitignore file.
Therefore, my .env file is not taken into account and is offered to me to be sent to git. How can I do?
How can i ignore my .env file ?
答案1
得分: 0
你可以将.env
行添加到你的.gitignore
中,保存更改后它将不会在你的代码库中被跟踪。
如果你已经提交了.env
,你可以使用Git的命令行工具移除它。
英文:
You can just add .env
line to your .gitignore
, it will not be tracked in your repository after you save the changes.
If you have already committed .env
, you can remove it using Git's CLI.
答案2
得分: 0
如您的截图所示,您的.env
文件已被跟踪并且已被修改。
如果文件已被跟踪,那么它就已被跟踪,.gitignore
不会产生任何影响。
您可以告诉Git假定文件没有更改,但这是一个非常危险的选项,因为如果您例如切换分支并且文件在分支之间不同等情况下,Git将高兴地覆盖它。
如果您不希望文件被跟踪,您需要取消版本控制它,例如使用git rm --cached .env
。并且在.gitignore
中,您可以添加/.env
以仅匹配在同一级别的文件系统条目。
英文:
As your screenshot shows, your .env
file is already tracked and has modifications.
If a file is tracked, it is tracked, and .gitignore
does not have any effect whatsoever.
You can tell Git to assume the file being unchanged, but that is a very dangerous option, because then Git will happily overwrite it if you for example switch branches and the file is different between the branches and so on.
If you do not want the file to be tracked, you need to unversion it, e.g. using git rm --cached .env
. And to .gitignore
you would add /.env
to match only the filesystem entry on the same level.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论