解决 .gitignore无效,不能过滤某些文件

1 新建 .gitignore文件

touch .gitignore 

2 然后打开文件

open .gitignore

3 添加忽略信息并保存

可是居然没有效果,后来谷歌才知道:
gitignore只能忽略那些原来没有被 track 的文件,如果某些文件已经被纳入了版本管理中,则修改 .gitignore 是无效的。解决方法是先把本地缓存删除,然后再提交。

刚开始新建一个项目可能会把.idea/workspace.xml等这种系统文件或编译中间过程的文件都用git add添加到了git版本库中来管理,这样即使后来添加了.gitignore文件也不能忽略掉已经添加到版本库中的文件,这时需要用

git rm --cache xxx

再在.gitignore中添加该文件从而实现了对该文件的忽略。。。(.gitignore 与 .git添加到同一级目录即可)

1.刚开始 使用的是 git rm -r -n */gengen”)
参数解释:-r 递归移除目录,(Allow recursive removal when aleading directory name is given.)
-n:加上这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览,所以一般用这个参数先看看要删除哪些文件,防止误删,确认之后,就去掉此参数,真正的删除文件。 (Don’t actually remove any file(s). Instead, just show if theyexist in the index and would otherwise be
removed by the command.)

参考博客

参考博客

猜你喜欢

转载自blog.csdn.net/nockinonheavensdoor/article/details/80324265