git状态说文件被删除但是git rm说错误: pathspec '.....' did not match any files

标签 git

我已经这样做了 100 多次。 我从目录中删除了一个文件,然后运行看起来不错的 git status。

# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php 
#

然后我跑 git rm themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php 并收到错误信息

error: pathspec 'themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php' did not match any file(s) known to git.

git status“知道”这个文件,但是 git rm 不知道也不会删除它。我被卡住了,该如何解决?

最佳答案

一个快速而肮脏的解决方案是添加回文件并使用

git rm themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php

删除它。

git rm 也会从文件系统中删除文件,因此您不需要(通常也不应该)手动删除文件。

编辑

一个更简洁的方法是让 git 注意到丢失的文件使用

git add -u

git commit -a

来自 git-add 的文档,这里是 -u 选项的描述

Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.

这是 git-commit

-a 选项

Tell the command to automatically stage files that have been modified and deleted, but new files you have not told git about are not affected.

关于git状态说文件被删除但是git rm说错误: pathspec '.....' did not match any files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14444245/

相关文章:

git - 删除远程分支时 Hook 拒绝更新问题

xcode - 为什么在我的 Mac 上运行的 Jenkins 不能连接到本地 git 仓库?

git - 列出未 merge 到上游的分支

git - 通过 SSH 将 Amazon EC2 与 GIT 连接时权限被拒绝

Git gc 显示错误 "Could not read commit"

eclipse - 在 Egit/TortoiseGit 中查看 repo 的整个提交历史的方法?

Git-SVN clone 这个什么时候结束?

macos - Git rebase 错误 : This application will not run on your computer

Git 后接收 [[ 未找到

git - TFS 服务 GitContinouslyDeploymentTemplate.12.xaml 无法加载参数