我做了这几百次.我从目录中删除了一个文件然后运行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
#
Run Code Online (Sandbox Code Playgroud)
然后我运行 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.
Run Code Online (Sandbox Code Playgroud)
git status"知道"该文件,但git rm没有,也不会删除它.我被困住了,我该如何解决这个问题?
一个快速而肮脏的解决方案是添加文件并使用
git rm themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php
Run Code Online (Sandbox Code Playgroud)
删除它.
git rm 从文件系统中删除文件,因此您不需要(通常不应该)手动删除文件.
编辑
更简洁的方法是让git注意丢失的文件
git add -u
Run Code Online (Sandbox Code Playgroud)
要么
git commit -a
Run Code Online (Sandbox Code Playgroud)
从文档中git-add,这里是-u选项的描述
仅匹配索引中已跟踪的文件而不是工作树.这意味着它永远不会暂存新文件,但它会暂存已修改的跟踪文件的新内容,并且如果已删除工作树中的相应文件,它将从索引中删除文件.
这是一个可供-a选择的git-commit
告诉命令自动暂存已修改和删除的文件,但是没有告诉git的新文件不受影响.