Rake task to remove all deleted files from git
April 9th, 2008
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
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
April 12th, 2008 at 05:32 PM
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.
May 5th, 2008 at 12:56 PM
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).