简体   繁体   中英

How to remove files deleted from .git?

When I delete a file (or rename it) by using mv , rm or some other facility, the file shows as deleted when I do 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

Before creating a commit, it is cumbersome to do git rm <file> for each file, particularly as there is no auto-completion in the terminal for a file which isn't there.

Is there a shorter way to remove the deleted files from the set of files tracked by git?

Thanks

I believe git add -u will do what you wish, from the documentation:

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

Reference: http://git-scm.com/docs/git-add

When you delete some files, remember to add "a" parameter in commit:

$ git commit -am 'Message'

"a" will automatically remove files from repository

Yes, git add -u should do the trick (it updates your index with all modifications/deletions). If you already added the file with its new file name, you will even see the rename in git status .

It's not exactly what you asked for, but you could try git commit -a . From the documentation:

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.

My answer does not really address this specific question, but...

Note that unlike certain other VCSes, in Git, the git rm command removes the file both from the index and the work tree unless told otherwise (using the --cached command-line option). So you're advised to delete your tracked files using git rm in the first place: you'll get your filename completion working and no need to mess with the syncing the state of the index with the work tree.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM