gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 01:18:18 27 4
gpt4 key购买 nike

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

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

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

下面我列出了目录内容、分支等。到目前为止,我已经尝试从目录中使用 rm,并转义以防万一出现有趣的字符,我真的很困惑。我搜索了网络和 SO 但找不到具体的内容。

$ 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

更新

@Nevik 和@Boris 的回答帮了大忙。我意识到我对正在发生的许多事情感到困惑,其中一些被 IntelliJ IDEA(我通常喜欢的工具,顺便说一句)加剧了。首先,来自 git rm 的“fatal: pathspec”消息既无用又具有误导性。

其次,我在 .gitignore 中有该文件,但在提出我的问题之前已将其删除。然而,它也独立于 git 包含在 IDEA 的忽略文件功能中,并在项目查看器中显示(而不是未跟踪,如 git status 所示)。最后,我在试验时运行了 IDEA,看起来它在我的 rm 之后立即重新创建了文件。

我的结论是,如果我对 Git 行为感到困惑,请确保在调试时退出 IDEA 并仅在命令行(和 gitk)中工作。

最佳答案

您的文件 .idea/workspace.xml 不受 git 版本控制。您尚未添加它(检查 git 状态/未跟踪文件)或忽略它(使用 .gitignore 或 .git/info/exclude 文件)

您可以使用以下列出所有忽略文件的 git 命令来验证它:

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

关于git - 无法删除真正存在的文件 - fatal : pathspec . .. 不匹配任何文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15931238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com