Friday, September 29, 2006

Remove Subversion from a tree

The following code will remove all the .svn folders from a tree (starting at the current file's directory).
Find.find(File.dirname(__FILE__)) { |path| `rm -rf #{path}` if path =~ /\.svn$/}
I've needed this enough times that I thought it might save someone else some time.

When did I use this? Every time I start a new project I check it into a local subversion repository. After working on the code for a bit, if I decide that it's a project worth distributing I register it somewhere else (such as RubyForge). If my project is accepted, I'll transfer the code to the projects repository. The easiest way, I've found, to move the code is to remove the local .svn directories and check out version 0 of the new repository into the project's root. At this point, I can svn add everything and check in.

I'm sure there's a better way, but this is simple and it works.


  1. Anonymous1:29 PM

    From the command line this also works:

    find ./ -name .svn -exec rm -fr {} \;

  2. Anonymous1:30 PM

    find . -name ".svn" -exec rm '{}' \;

  3. Anonymous1:32 PM

    Ah, ships crossing in the night. He's right, though. I forgot -rf.

  4. Anonymous1:35 PM

    @jonathan and evan

    Thanks, my command line-fu is weak. =)

  5. require 'fileutils'



  6. Anonymous1:26 AM

    I use this in my Apache config:
    RewriteRule \.svn .nosvnallowed

    Then I just have a current checkout in my DocumentRoot dir and when I want to update my website I just do an svn up in place. Since the .svn components are rewrtten there's no way anybody can access those files from outside. This is faster than the other options especially for bigger sites because you don't have to recopy the entire website, but instead just update the pages that have changed.

    Best regards,

    Rudi Cilibrasi

  7. Anonymous4:30 PM

    svn export {url of project tree} {local directory}

  8. Anonymous9:46 PM

    find . -type d -name ".svn" -exec rm -rf {} \;


Note: Only a member of this blog may post a comment.