问题:
在使用git进行版本控制的过程中发现,将想被忽略的文件(文件夹)配置到.gitignore文件中后,实际修改了想被忽略的文件,调用git status查看时,仍然会提示提交这些文件。也就是说实际并没有被忽略
原因:
原因是git ignore只会对不在git仓库中的文件进行忽略,如果这些文件已经在git仓库中,则不会忽略。所以如果需要忽略的文件已经提交到本地仓库,则需要从本地仓库中删除掉,如果已经提交到远端仓库,则需要从远端仓库中删除。删除.gitignore文件才能实际生效。
解决:
** 根本原因 **
.gitignore文件只是ignore没有被staged(cached)文件,对于已经被staged文件,加入ignore文件时一定要从staged移除。下面是来自github的一段话:
If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
$ git rm --cached file_to_ignore
git ls-files --deleted | xargs git rm --cached
git commit
浙公网安备 33010602011771号