我已经这样做了 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/