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.
Solution 1:
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 .
Solution 2:
git ls-files --deleted -z | xargs -0 git rm
might be what you are looking for.. it works for me..
Solution 3:
You can use
git add -u
To add the deleted files to the staging area, then commit them
git commit -m "Deleted files manually"
Solution 4:
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 -z | xargs -0 git rm
git commit
Solution 5:
You're probably looking for -A:
git add -A
this is similar to git add -u, but also adds new files. This is roughly the equivalent of hg's addremove
command (although the move detection is automatic).