git对已经提交过的文件添加到.gitignore

摘自:https://blog.csdn.net/hnjb5873/article/details/108774212

git之前已经提交过的文件,在开发过程中,此文件需要忽略,添加到了.gitignore,但是再次提交的时候,该文件依旧被跟踪。处理办法如下:

为了避免冲突,先pull远程仓库到本地
git pull
删除本地项目目录的缓存
git rm -r --cached .
编辑gitignore,将需要忽略的添加进来
再次add仓库路径下的所有文件
git add .
再次执行commit命令
git commit -m "add .gitignore"
最后,提交到远程仓库
git push

原文地址:https://www.cnblogs.com/linwenbin/p/15312130.html