【问题标题】:Git - rm --cached .idea and fatal pathspecGit - rm --cached .idea 和致命路径规范
【发布时间】:2014-08-04 15:59:40
【问题描述】:

我正在使用 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 rm --cached .idea/ 从 git index 中删除它时,我得到了错误

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

我做错了什么?

【问题讨论】:

    标签: git intellij-idea phpstorm git-rm


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        移动到目录并运行

        git rm -rf --cached .idea
        

        别忘了将它添加到您的.gitignore 文件中!

        【讨论】:

          猜你喜欢
          • 2012-09-15
          • 1970-01-01
          • 2011-05-07
          • 1970-01-01
          • 2011-08-13
          • 2021-04-02
          • 2023-03-16
          • 1970-01-01
          • 2016-01-30
          相关资源
          最近更新 更多