Git - rm --cached .idea和致命的路径规范

时间:2014-08-04 15:59:40

标签: git intellij-idea phpstorm git-rm

我正在使用PHPstorm,我想从git index中删除隐藏文件夹.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 rm --cached .idea/从git索引中删除它时,我收到了错误

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\'

我做错了什么?

3 个答案:

答案 0 :(得分:3)

&#34;未跟踪&#34; file是当前索引(AKA登台区域)中当前(&#34; HEAD&#34;)提交, 的文件。

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

如果路径不在索引中,并且&#34;未跟踪&#34;意味着必须是这种情况 - 然后你要求git将其从索引中删除,你想要什么错误? : - )

如果你想让git(1)继续保持未跟踪的路径,(2)只是关闭它,请参阅gitignore

答案 1 :(得分:0)

git没有跟踪

.idea。您无法从存储库中删除它。您可能想要做的是通过adding the directory to the .gitignore file将其从git中排除。

答案 2 :(得分:0)

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

移动到目录并运行

git rm -rf --cached .idea

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

相关问题