gitignore - Specifies intentionally untracked files to ignore
.gitignore官方文档
A gitignore
file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected
To stop tracking a file that is currently tracked, use git rm --cached
to remove the file from the index. The filename can then be added to the .gitignore
file to stop the file from being reintroduced in later commits.
原因
.gitignore
文件只会作用于未跟踪(untracked)的文件,如果需要作用于已经跟踪(tracked)的文件,加入ignore文件时需要先停止跟踪(stop tracking)从暂存中删除才会生效
解决方法
1 | git rm -r --cached . |