git 无法删除 .idea 目录

【字号: 日期:2023-10-25浏览:38作者:雯心

问题描述

根目录下有一个 .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 filesAdministrator@PC-20140703LOZL /D/PC/ppgame (master)$ git rm --cached .ideafatal: pathspec ’.idea’ did not match any filesAdministrator@PC-20140703LOZL /D/PC/ppgame (master)$ git rm --cached .idea/*.*fatal: pathspec ’.idea/encodings.xml’ did not match any filesAdministrator@PC-20140703LOZL /D/PC/ppgame (master)$ git rm --cached .idea*fatal: pathspec ’.idea’ did not match any filesAdministrator@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 .ideafatal: pathspec ’.idea’ did not match any filesAdministrator@PC-20140703LOZL /D/PC/ppgame (master)$ git push -u orign --allfatal: ’orign’ does not appear to be a git repositoryfatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.Administrator@PC-20140703LOZL /D/PC/ppgame (master)$ git push -u orign/master --allfatal: ’orign/master’ does not appear to be a git repositoryfatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.Administrator@PC-20140703LOZL /D/PC/ppgame (master)$

问题解答

回答1:

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

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

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

git add -A .提交git pull

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

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

回答2:

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

回答3:.gitignore 先不添加忽略的那行,直接删除 .idea 文件,然后提交打开 .gitignore 里添加 .idea/*提交 .gitignore,over回答4:

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

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

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

回答5:

# 执行步骤如下:

先将来 .idea/ 添加到文件。ignore文件中。2.删除本地。idea文件

3.git add 。

git commit -m 'update .ignore file'

git push origin master6.用本地的idea打开文件,会看到本地的.idea文件又回来了。

相关文章: