Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I commit all deleted files in Git? [duplicate]

I have a Git repo that I have deleted four files from using rm (not git rm), and my Git status looks like this:

#    deleted:    file1.txt #    deleted:    file2.txt #    deleted:    file3.txt #    deleted:    file4.txt 

How do I remove these files from Git without having to manually go through and add each file like this:

git rm file1 file2 file3 file4 

Ideally, I'm looking for something that works in the same way that git add . does, if that's possible.

like image 897
Codebeef Avatar asked Jan 29 '09 17:01

Codebeef


People also ask

Do I add deleted files to git commit?

To add a single file to the commit that you've deleted, you can do git add what/the/path/to/the/file/used/to/be . This is helpful when you have one or two deletions to add, but doesn't add a batch of deletions in one command.

How do I remove a deleted file from my git repository?

Delete Files using git rm. The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

What is git add rm?

git rm is used to remove a file from a Git repository. It is a convenience method that combines the effect of the default shell rm command with git add .


2 Answers

For Git 1.x

$ git add -u 

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

For Git 2.0

To stage your whole working tree:

$ git add -u :/ 

To stage just the current path:

$ git add -u . 
like image 98
carl Avatar answered Sep 20 '22 18:09

carl


git ls-files --deleted -z | xargs -0 git rm  

might be what you are looking for.. it works for me..

like image 23
Varinder Avatar answered Sep 17 '22 18:09

Varinder