Last Updated: February 25, 2016
·
4.672K
· futuraprime

Removing deleted files from a git commit

Often, I've deleted a bunch of files and then find I the change is still unstaged.

# On branch master
# 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:    js/foo.js
#   deleted:    js/bar.js

Now I've got to manually remove those all from my commit.

Well, not so fast. Just do this command:

git ls-files -dz | xargs -0 git rm

and presto! All the removals will be staged. (Note: using the -z and -0 flags is optional—they prevent filenames with spaces from screwing up the command.)

2 Responses
Add your response

$git commit -a <br />
does this command is capable to do it..?

over 1 year ago ·

No, git commit -a won't do it. That adds all modified files, but it won't add new files or remove deleted ones.

git add . won't do it either—it adds modified and new files, but won't remove old ones.

over 1 year ago ·