如何删除从.git中删除的文件?

如何删除从.git中删除的文件?,git,Git,当我使用mv、rm或其他工具删除(或重命名)文件时,当我执行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) # # del

当我使用
mv
rm
或其他工具删除(或重命名)文件时,当我执行
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:    ../src/main/..../myFile.java
#未为提交而暂存的更改:
#(使用“git add/rm…”更新将提交的内容)
#(使用“git签出--…”放弃工作目录中的更改)
#
#已删除:../src/main/…/myFile.java
在创建提交之前,为每个文件执行
git-rm
是很麻烦的,特别是当终端中没有自动完成不存在的文件时

有没有一种较短的方法可以从git跟踪的文件集中删除已删除的文件


谢谢

这并不是你想要的,但是你可以试试
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.
-u
--update
  Only match <filepattern> 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 file
  in the working tree have been removed.

是的,
git add-u
应该可以做到这一点(它通过所有修改/删除更新索引)。如果您已经添加了具有新文件名的文件,您甚至会在
git status

中看到重命名,我相信
git add-u
会按照您的意愿从文档中看到:

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.
-u
--update
  Only match <filepattern> 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 file
  in the working tree have been removed.
-u
--更新
仅与索引中已跟踪的文件匹配
而不是工作树。这意味着它永远不会上演新的一幕
文件,但它将暂存已修改的跟踪文件的新内容
如果相应的文件
已删除工作树中的。

参考:

删除某些文件时,请记住在提交中添加“a”参数:

$ git commit -am 'Message'

“a”将自动从存储库中删除文件

我的回答并没有真正解决这个具体问题,但是


请注意,与某些其他VCSE不同,在Git中,
Git rm
命令会从索引和工作树中删除文件,除非另有说明(使用
--cached
命令行选项)。因此,建议您首先使用
git rm
删除跟踪的文件:这样您的文件名就可以完成了,无需将索引的状态与工作树同步。

我通常只需复制并粘贴到文本编辑器中,然后查找并替换即可一次性批处理。是,但有时我会在文本编辑器中重命名文件。由于文件可能位于树的深处,因此键入
git rm
和文件的完整路径可能需要更多时间。
git mv
在您的情况下,是的,否则我同意。