最佳答案
无法删除真正存在的文件——致命的: pathspec... 不匹配任何文件
我有一个在 git 控制下的文件,它不会被删除。失败的命令是:
$ git rm .idea/workspace.xml
fatal: pathspec '.idea/workspace.xml' did not match any files
下面我列出了目录的内容、分支等。到目前为止,我已经尝试从目录中的 rm,并转义,以防有有趣的字符,我真的被难住了。我在网上搜索了一下,但是没有找到这个。
$ git branch -a
* dot-output
master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/modelspace
$
$ git status
# On branch dot-output
# Untracked files:
# ...
$ ls .idea/
ant.xml encodings.xml modules.xml workspace.xml
compiler.xml inspectionProfiles scopes
copyright libraries testrunner.xml
dictionaries misc.xml vcs.xml
$ ls -al
total 56
drwxr-xr-x 16 matt staff 544 Apr 10 11:33 .
drwxr-xr-x@ 33 matt staff 1122 Apr 10 09:40 ..
-rw-r--r--@ 1 matt staff 12292 Apr 10 11:19 .DS_Store
drwxr-xr-x 18 matt staff 612 Apr 10 11:39 .git
-rw-r--r-- 1 matt staff 98 Mar 6 13:40 .gitignore
drwxr-xr-x 16 matt staff 544 Apr 10 11:34 .idea
-rw-r--r-- 1 matt staff 1113 Feb 25 11:07 README
...
$ head -n 2 .idea/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
$ git rm .idea/workspace.xml
fatal: pathspec '.idea/workspace.xml' did not match any files
“内维克和鲍里斯”的回答很有帮助。我意识到我被许多事情搞糊涂了,其中一些被 IntelliJ IDEA (一个我通常喜欢的工具,顺便说一下)加剧了。首先,来自 git rm
的“致命的: pathspec”消息既没有帮助,也具有误导性。
其次,我在 .gitignore
中有这个文件,但在问我问题之前已经删除了它。但是,它也包含在 IDEA 的 Ignored Files 特性中,与 git 无关,并且在项目查看器中显示(而不是像 git status 显示的那样未被跟踪)。最后,我在实验时运行了 IDEA,它看起来像是在我的 rm
之后立即重新创建文件。
我得出的结论是,如果我对 Git 的行为感到困惑,请确保在调试时退出 IDEA 并仅在命令行(和 gitk)中工作。