tags:

views:

1210

answers:

4

If I delete some files from the disk they come up as deleted like so:

C:\git\bc>git status
# On branch tracking2
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    test.txt
#

Is there a way to do a one command "just delete these files from the repository"? Sort of similarly to git add . which would add all new and modified files.

EDIT I use Visual Studio and Windows explorer to work with my source tree and at some point I just delete a whole bunch of files. I then find it a pain to call git rm as the files are no longer around and there is no command line intellisense to help me type it in. So I want a command that just deletes all files from git that are deleted from the disk.

+17  A: 

Try this:

$ git add -u

This tells git to automatically stage tracked files -- including deleting the previously tracked files.

carl
Brilliant, that's exactly what I need.
Igor Zevaka
+1  A: 

git rm test.txt

Before or after you deleted the actual file.

Peaker
While it'll work, I often find myself deleting a ton of files through just `rm` and regretting it later.
carl
+2  A: 
git add .    
git commit -a -m "Custom Message"

Note this will commit everything, including deleted files. But at least for me, it's what I do most of the time...

Samuel Carrijo
`git add .` does not mark deleted files for deletion from git.
Igor Zevaka
Well, my hint is for commiting everything. You could jump this part...
Samuel Carrijo
+7  A: 

If you simply run:

git add -u

git will update its index to know that the files that you've deleted should actually be part of the next commit. Then you can run "git commit" to check in that change.

Or, if you run:

git commit -a

It will automatically take these changes (and any others) and commit them.

Update: If you only want to add deleted files, try:

git ls-files --deleted | xargs git rm
git commit
Emil
Right, `git commit -a` will do what I want, except in some cases I have files that I don't want to commit, so i want to prepare the commit manually.
Igor Zevaka
commit -a essentially does an "add -u" first; it will update the index with any changes to known files (be they deletions or simple changes). You can of course be more specific and add/rm only the files you want.http://git.or.cz/gitwiki/GitFaq#Whyis.22gitrm.22nottheinverseof.22gitadd.22.3F may be helpful.
Emil