Last Updated: February 25, 2016
·
276
· mikkkee

Git remove deleted files

Sometimes I forget to delete files in a git repository using git rm, leaving lots of deleted files in Changes not staged for commit.

I can still use git rm <deleted file name> to stage the deletion. But what if I have dozens of files to delete? Not to say I may mistype the file names since shell cannot tab-complete names of deleted files.

  • Use git rm directly. This may not work on Windows.
git rm $(git ls-files --deleted)
  • Use xargs to pass parameters to git rm. This works perfectly on both *nix and Windows.
git ls-files --deleted -z | xargs -0 git rm