DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Remove Deleted Files From Git

06.18.2008
| 46907 views |
  • submit to reddit
        // Via http://www.jamesrobey.com/bash-script-to-remove-deleted-files-from-git/

for i in `git status | grep deleted | awk '{print $3}'`; do git rm $i; done
    

Comments

Snippets Manager replied on Thu, 2011/05/19 - 11:25am

you probably search: git add -u

Snippets Manager replied on Sun, 2011/04/17 - 12:27pm

Mafro's post seems the most effective. If you wrap it in quotes it will even work with paths with spaces, the others fail. git rm "$(git ls-files -d)"

Snippets Manager replied on Wed, 2009/07/15 - 5:05am

bash code which is the cleanest (in my humble opinion): $ git rm $(git ls-files -d)

Snippets Manager replied on Mon, 2012/05/07 - 2:58pm

I'm not sure, but I think that's what "git clean" is for. Maybe "git clean -f" ?

Snippets Manager replied on Tue, 2009/01/06 - 3:21am

I was looking for this, but now found that git add -u It deletes all removed files and updates what was modified. Just doesn't add new files. It's better because if you have a file named "deleted.txt" it will also be removed.

Snippets Manager replied on Tue, 2008/06/10 - 4:11pm

Actually... this works better :) git ls-files --deleted | xargs git rm

Snippets Manager replied on Tue, 2008/06/10 - 4:11pm

One way, put the line in a shell script and create an alias in ~/Users/you/.bash_profile alias git-rm-after='sh /path/to/git-remove-after.sh'

Snippets Manager replied on Tue, 2008/06/10 - 4:11pm

great! this is one of the features I miss from mercurial when using git. How could you add an alias for this?