After shuffling some code around I found myself with a lot of files to remove from git. Instead of doing it by hand or trying to ensure a subdirectory is gone and use -r, I wrote this rake task:

namespace :git do
  desc "Remove removed files"
  task :remove do
    system("for i in $(git status | grep deleted | awk ‘{print $3}’); do git rm $i; done")
  end
end

If you use sake, this task is available on pastie @ sake -T http://pastie.caboo.se/177861.txt

2 Responses to “Rake task to remove all deleted files from git”

  1. Kevin Triplett Says:

    Awesome -- I had a huge list of deleted files and was dreading manually git rm'ing them all. (For anyone cutting and pasting directly from the browser output, make sure you change the ticks above into single quotes.) Thanks, Brian, you saved my fingers.

  2. David Phillips Says:

    This is inefficient and breaks if filenames have spaces or contain the word "deleted". All you need is "git add -u" to update everything that git knows about (i.e. modified and deleted files are updated in the index, but new files are not added).

Leave a Reply