本文介绍了无法删除真正存在的文件 - fatal:pathspec ...与任何文件都不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法删除真正存在的文件 - fatal:pathspec ...与任何文件都不匹配



我有一个git控制下的文件,它不会被删除。失败的命令是:

  $ git rm .idea / workspace.xml 
fatal:pathspec'.idea / workspace .xml'不匹配任何文件

下面列出了目录内容,分支等等。我已经从目录中尝试了rm,并且为了万一有趣的角色而逃跑,而且我真的很难过。我搜索了网页,但没有具体找到它。

  $ git分支-a 
*点输出

遥控器/原点/ HEAD - >原产地/主产地
遥控器/原产地/主产地
遥控器/产地/模型空间
$

$ git状态
#在分支点输出
#未写入文件:
#...

$ ls .idea /
ant.xml encodings.xml modules.xml workspace.xml
compiler.xml inspectionProfiles范围
版权库testrunner.xml
字典misc.xml vcs.xml

$ ls -al
共56
drwxr-xr-x 16亚光工作人员544 4月10日11:33。
drwxr-xr-x @ 33 matt matt 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.0encoding =UTF-8?>
< project version =4>

$ git rm .idea / workspace.xml
fatal:pathspec'.idea / workspace.xml'不匹配任何文件

更新:Nevik和Boris的回答非常有帮助。我意识到我对许多事情感到困惑,其中一些因IntelliJ IDEA(我一般喜欢的工具,BTW)而加剧。首先,来自git rm的'致命:pathspec'信息既没有帮助也没有误导(在这个香草用户看来)。其次,我有.gitignore中的文件,但是在提出我的问题之前删除了它。然而,它也包含在独立于git的IDEA的忽略文件功能中,并在项目查看器中显示(不是未跟踪,因为git状态显示)。最后,我在试验时运行了IDEA,看起来它是在我的RM之后立即重新创建文件。所以,我的结论是,如果我对Git行为感到困惑,请务必在调试时退出IDEA并在命令行(和gitk)中工作。而SO用户真棒。再次感谢!

解决方案

您的文件 .idea / workspace.xml 为不在git版本控制下。你可能还没有添加它(检查git status / Untracked文件)或忽略它(使用.gitignore或.git / info / exclude文件)

你可以验证它使用下面的git命令,列出所有被忽略的文件:

  git ls-files --others -i --exclude-standard 


unable to remove file that really exists - fatal: pathspec ... did not match any files

I have a file under git control that simply will not be deleted. The failing command is:

$ git rm .idea/workspace.xml
fatal: pathspec '.idea/workspace.xml' did not match any files

Below I list the directory contents, branches, etc. So far I've tried rm from within the directory, and escaping just in case there are funny characters, and I'm really stumped. I searched the web and SO but couldn't find this specifically. Thanks in advance!

$ 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

UPDATE: Answers from Nevik and Boris helped a lot. I realized that I was confused by a number of things going on, some of which were exacerbated by IntelliJ IDEA (a tool I generally love, BTW). First, the 'fatal: pathspec' message from git rm is both unhelpful and misleading (in this vanilla user's opinion). Second, I had the file in .gitignore, but had removed it before asking my question. However, it was also included in IDEA's Ignored Files feature independently of git, and showed as such in the project viewer (instead of untracked, as git status showed). Finally, I had IDEA running while I was experimenting, and it looks like it was recreating the file immediately after my rm. So, my takeaway is that if I'm getting confusing Git behavior, make sure to quit IDEA and work soley in the command line (and gitk) while debugging. And that SO users are awesome. Thanks again!

解决方案

Your file .idea/workspace.xml is not under git version control. You have either not added it yet (check git status/Untracked files) or ignored it (using .gitignore or .git/info/exclude files)

You can verify it using following git command, that lists all ignored files:

git ls-files --others -i --exclude-standard

这篇关于无法删除真正存在的文件 - fatal:pathspec ...与任何文件都不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:25