0

我正在使用 PHPstorm,我想从 git 索引中删除隐藏文件夹 .idea。当我使用时,$git status我得到了

C:\Program Files (x86)\Ampps\www\1stenglish IS [master +1 ~0 -0 !]> git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .idea/
nothing added to commit but untracked files present (use "git add" to track)

但是当我想用命令从 git index 中删除它时,git rm --cached .idea/我得到了错误

fatal: pathspec '.idea' did not match any files

我尝试了不同的路径选项,但没有结果:

git rm --cached .idea
git rm --cached .idea/*
git rm --cached 'C:\Program Files (x86)\Ampps\www\1stenglish IS\.idea'
git rm --cached 'C:\Program Files (x86)\Ampps\www\1stenglish IS\.idea\'

我做错了什么?

4

3 回答 3

6

“未跟踪”文件既不在当前(“HEAD”)提交中,也不在当前索引(AKA 暂存区)中。

git rm --cached告诉 git 从当前索引中删除某些内容。

如果路径不在索引中——并且“未跟踪”意味着一定是这种情况——然后你要求 git 将它从索引中删除,你想要什么错误?:-)

如果您希望 git (1) 继续不跟踪路径,并且 (2) 只是闭嘴,请参阅gitignore

于 2014-08-04T16:08:55.403 回答
0

.idea尚未被 git 跟踪。您无法将其从存储库中删除。您可能想要做的是通过将目录添加到.gitignore文件中将其从 git 中排除。

于 2014-08-04T16:09:29.633 回答
0

问题可能是因为您不在要删除的文件的目录中。

移动到目录并运行

git rm -rf --cached .idea

并且不要忘记将其添加到您的.gitignore文件中!

于 2020-09-28T12:37:23.693 回答