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.)
Written by Evan Hensleigh
Related protips
2 Responses
$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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#