git - 尽管我的 .gitignore 为何我的配置文件仍被 checkin ?

标签 git gitignore

我的 .gitignore 有以下内容:

./config.json

但是当我进行更改时,我的 config.json 仍在提交。

为什么会发生这种情况?

最佳答案

如果您的文件在添加到 gitignore 之前已添加到存储库,则应明确将其从存储库中删除

git rm config.json
git commit <message>

从存储库中删除后,该文件将按预期被忽略。

如果您想将此文件保存在文件系统中,可以使用--cached删除选项

git rm --cached config.json

关于git - 尽管我的 .gitignore 为何我的配置文件仍被 checkin ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50197130/

相关文章:

git - 如何使用 github webhooks 阻止特定的推送?

git - 虚拟环境 : Connection in use error

git - 如何跟踪 Git 中共享公共(public)代码的多个项目?

git - 如何使用 PhpStorm 和 Git 忽略文件?

git - 有什么方法可以告诉 git 忽略文件的某些行吗?

ios - Jenkins 和 CocoaPods

python - 尝试解析标签时德威治的 NotCommitError

gitignore:了解 "hello/"与 "hello/*"

javascript - 当我的 API key 在 .gitignore 文件中时,如何从 git 部署到 heroku?

Git 忽略子目录中的文件