我正在使用Laravel 5中的codeception,我在我的基础项目目录中有一个codeception.yml文件,我想忽略它,因为它的数据库凭据因机器而异。
.gitignore 档案:
/.phpstorm.meta.php
/_ide_helper.php
/vendor
/node_modules
Homestead.yaml
Homestead.json
.env
.env.testing
codeception.yml
我认为应该这样做。但是git仍在跟踪文件。我做错了什么?
答案 0 :(得分:1)
如果您以前提交过该文件,则需要将其从缓存中删除尝试
git rm --cached codeception.yml
即使你将文件/目录添加到.gitignore
文件中,如果它已经被添加到过去的仓库中,那么git会记住它。
它的数据库凭据因机器而异。
如果您不小心提交了敏感数据,可能需要遵循建议Github give here。
为防止链接损坏,请参阅以上链接中有关从存储库中删除安全数据的摘要说明。如果您愿意,还可以使用BFG Repo-Cleaner包来实现更简单的版本。
cd
中。 运行以下(小心!这将覆盖现有标签。):
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch codeception.yml' \
--prune-empty --tag-name-filter cat -- --all
codeception.yml
文件添加到.gitignore
并提交。 git push origin --force --all
git push origin --force --tags
经过一段时间后,您确信git filter-branch没有意外的副作用,您可以强制取消引用本地存储库中的所有对象并使用以下命令进行垃圾回收(使用Git 1.8 .5或更新):
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
然后
git reflog expire --expire=now --all
然后
git gc --prune=now
答案 1 :(得分:0)
您可能已经将codeception.yml文件添加到git索引,然后再将其添加到.gitignore。这就是git跟踪它的原因。
您可以使用以下命令将其从git索引中删除,以便不再跟踪它。但请记住,除了本地副本之外,这将删除推送这些更改后拉取的所有其他位置的codeception.yml文件。
git rm --cached codeception.yml