5

当我使用或其他工具删除文件(或重命名)时mv,文件显示为已删除:rmgit 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 rm <file>,尤其是在终端中没有自动完成不存在的文件的情况下。

是否有更短的方法可以从 git 跟踪的文件集中删除已删除的文件?

谢谢

4

5 回答 5

4

从文档中,我相信git add -u会做你想做的事:

-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.

参考: http: //git-scm.com/docs/git-add

于 2012-07-15T00:02:47.883 回答
3

当你删除一些文件时,记得在提交中添加“a”参数:

$ git commit -am 'Message'

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

于 2012-07-15T00:53:43.940 回答
2

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

于 2012-07-15T00:01:53.827 回答
1

这不完全符合您的要求,但您可以尝试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.
于 2012-07-14T23:59:57.577 回答
1

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

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

于 2012-07-15T12:06:03.907 回答