about:benjie

Random learnings and other thoughts from an unashamed geek

SVN Hint: Automatically Removing Manually Deleted Files From SVN

| Comments

Bash

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:

Tell SVN to delete the files that you’ve deleted without telling SVN.
1
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:

  1. 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!
  2. 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.
  3. Use at your own risk. The code is simple enough so you should be able to grok what it does.

Enjoy!

Comments