项目刚开始时,会在 gitignore 文件中将不需要纳入版本控制的目录或文件写入到里面,但是有时候考虑不周,有些应该忽略的目录和文件没有写入,如果要在 gitignore 文件中新增忽略目录或文件,首先修改修改 gitignore 文件,然后执行一下命令:
git rm -r --cached . #清除缓存
git add . # 重新 trace file
git commit -m "update .gitignore" #提交变更并注释
git push origin master #如果需要同步到remote的主分支的话
这样就可以时 gitignore 文件新增的目录或文件被忽略。