SVN Hint: Automatically removing manually deleted files from SVN

Bash
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:

  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!

Reblog this post [with Zemanta]

Tags: , , , , , , ,

Bookmark and Share

4 Responses to “SVN Hint: Automatically removing manually deleted files from SVN”

  1. about:benjie » Blog Archive » Useful Bash Scripts Says:

    [...] You might also be interested in my previous “whoops I deleted files without telling svn” post here. [...]

  2. John Gallagher Says:

    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.

  3. Benjie Says:

    You’re welcome John, thanks for letting me know it’s useful – it encourages me to put up more things I discover!

  4. Jasper Says:

    I normally realise straight away, revert and svn delete. Useful little snippet, though; ~/.profile’d!

Leave a Reply