簡體   English   中英

如何刪除從.git中刪除的文件?

[英]How to remove files deleted from .git?

當我使用mvrm或其他工具刪除文件(或重命名)時,當我執行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 rm <file>是很麻煩的,特別是因為終端中沒有自動完成的文件不存在。

是否有更短的方法從git跟蹤的文件集中刪除已刪除的文件?

謝謝

我相信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

刪除某些文件時,請記住在commit中添加“a”參數:

$ git commit -am 'Message'

“a”將自動從存儲庫中刪除文件

是的, git add -u應該做的伎倆(它用所有的修改/刪除來更新你的索引)。 如果您已經使用新文件名添加了文件,您甚至會在git status看到重命名。

這不完全是你要求的,但你可以嘗試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.

我的回答並沒有真正解決這個具體問題,但......

請注意,與某些其他VCS不同,在Git中, git rm命令會從索引工作樹中刪除該文件,除非另有說明(使用--cached命令行選項)。 因此,建議您首先使用git rm刪除跟蹤文件:您將完成文件名完成工作,無需將索引狀態與工作樹同步。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM