首页 > git 无法删除 .idea 目录

git 无法删除 .idea 目录

根目录下有一个 .idea 文件夹,我已经在 根目录下的 .gitignore 文件中加入了

.idea/*
.idea*
\.idea*

然后 git commit -m "ignore .idea dir" -> git push -u origin ->
但是远程的git 中还是有 .idea 这个目录。无法删除。

Administrator@PC-20140703LOZL /D/PC/ppgame (master)
$ git rm --cached .idea/*
fatal: pathspec '.idea/encodings.xml' did not match any files

Administrator@PC-20140703LOZL /D/PC/ppgame (master)
$ git rm --cached .idea
fatal: pathspec '.idea' did not match any files

Administrator@PC-20140703LOZL /D/PC/ppgame (master)
$ git rm --cached .idea/*.*
fatal: pathspec '.idea/encodings.xml' did not match any files

Administrator@PC-20140703LOZL /D/PC/ppgame (master)
$ git rm --cached .idea*
fatal: pathspec '.idea' did not match any files

Administrator@PC-20140703LOZL /D/PC/ppgame (master)
$ git rm --cached \.idea*
fatal: pathspec '.idea' did not match any files

1)如何才可以删除git中跟踪的 .idea目录但是又不删除本地的 .idea 文件夹?
2)是不是遇到文件夹中有. 这样特殊字符的,在.gitignore中需要转义?


我使用了 git rm -r --cached .idea 但是报错,删除不了。远程还在


Administrator@PC-20140703LOZL /D/PC/ppgame (master) $ git rm -r --cached .idea fatal: pathspec '.idea' did not match any files Administrator@PC-20140703LOZL /D/PC/ppgame (master) $ git push -u orign --all fatal: 'orign' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Administrator@PC-20140703LOZL /D/PC/ppgame (master) $ git push -u orign/master --all fatal: 'orign/master' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Administrator@PC-20140703LOZL /D/PC/ppgame (master) $

  1. 使用 git rm -fr .idea 删除本地.idea文件,

  2. 在.gitignore文件中添加.idea 进行过滤

  3. 保存后提交到远端,然后就发现已经清楚掉啦


你要先去删除远程的 .idea 目录。

这种情况,你是在设计gitignore 之前就没考虑好的,现在的措施是:

rm -rf .idea (这样会删掉你本地的,不过你重新打开一次项目就有会自动给你生成了)

git add -A .
提交
git pull

pull 后再看看同步后,远程的删掉没有;如果本地有,再次重复下。

干净后,这下 git rm -r --cached .idea 取消跟踪
在push 吧


已经在git跟踪的文件,在gitignore文件中写是不行的。


  1. .gitignore 先不添加忽略的那行,直接删除 .idea 文件,然后提交
  2. 打开 .gitignore 里添加 .idea/*
  3. 提交 .gitignore,over
【热门文章】
【热门文章】