SVN Hint: Automatically removing manually deleted files from SVN

- Image via Wikipedia
When deleting files in a working copy of an SVN repository you should do it on the command line: svn rm [filename]. If, however, you don’t do this (e.g. delete through a gui, or just do “rm” without the “svn“) then SVN gets confused, and puts a “!” in it’s status before all the deleted files. If you svn update, all the files will be recovered, rendering all your time spent deleting them wasted. Really you should use svn rm, but if it’s already too late for that, you can use this bash fragment to delete the files from SVN:
svn status | grep "^\!" | sed 's/^\! *//g' | xargs svn rm
This command does a status command, finds all lines starting with “!“, and then extracts the filename and runs it through “svn rm” – really deleting the file.
Caveats:
- Manually deleted files are not the only things that makes svn use “!” – so beware of this! Ensure you do really want to delete all those files!
- This works for filenames which are all_one-word/without/any.spaces but I am not sure if it will work or not for filenames with spaces in.
- Use at your own risk. The code is simple enough so you should be able to grok what it does.
Enjoy!
Related articles by Zemanta
- Save Your Skin by Customizing Your Bash Prompt (ghacks.net)
- Moving Directories in a SVN Repository using Tortoise SVN (modhul.com)
Tags: Bash, Command-line interface, Grep, Linux, sed, Shell, Subversion, svn

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_c.png?x-id=fb66b461-1ba1-4d58-a645-8eded5ab2ab4)
April 7th, 2009 at 7:54 pm
[...] You might also be interested in my previous “whoops I deleted files without telling svn” post here. [...]
July 2nd, 2009 at 5:05 pm
Holy cow. Thanks so much for this. Not being able to delete a file using the GUI was driving me up the wall. Why do tools like svn FORCE users to work in a specific way that’s awkward? There’s NO WAY I’m going to do an svn rm to remove every single file I want to delete – it’s just stupid.
Thanks again for making a simple line of code that fixes my problem and has saved me many hours.
July 2nd, 2009 at 8:29 pm
You’re welcome John, thanks for letting me know it’s useful – it encourages me to put up more things I discover!
July 2nd, 2009 at 11:23 pm
I normally realise straight away, revert and svn delete. Useful little snippet, though; ~/.profile’d!