How to remove all .svn subdirs from a given directory

Well.. Sometimes I'm a smart (or you might call it lazy) folk, so I do reuse my code. And the code is usually is stored inside a Subversion system, and several projects are always checked out to my local computer and therefore have these invisible .svn sub-directories all-over the place.
Being lazy (or you call it smart? :) to checkout stuff I need to be duplicated from a previous project into a current one, I usually just copy, say, "tiny_mce" folder from an old project to a new one.

The problem that appears when I try to do that and add the newly duplicated folder to the new project, is that svn complains the folder is already being under version control. Well of course, because all these .svn dirs were copied along with the "meat" :) What's the easiest way to remove .svn directories from that directory? If you're on a Mac or some other Unix-based system, that is.

Look no further than for the code below!

cd /path/to/your/dir

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

Voila. After some complaining about some .svn dirs couldn't be found (and you just safely ignore them) - you have a clean directory structure which you can than safely add to version control using everyone's favourite "svn add tiny_mce" (or whatever).

Mostly a note to myself, but hopefully it'll save somebody some time some day :)

Oh and of course you can just as easily remove dirs or files with a different file names, just bu replacing the ".svn" with, say, "Icon.icn" or something like that.

4 Responses to “How to remove all .svn subdirs from a given directory”

  1. Dean Says:

    Thanks Matt

    Been looking for an elegant solution to this problem for a couple of days.

    Saved me a load of pain :-)

    Dean

  2. Torrey Says:

    This is what svn export is for. Just run 'svn export srcdir ~/targetdir '. It will export the 'meat' and not the .svn dirs from the srcdir to the targetdir

  3. mike Says:

    Yep. But sometimes you just want to copy a versioned directory structure to a different location (another project, another dir of the same project, etc).

    There are, of course, svn copy and svn move (and of course svn export) commands which leave you with a proper directory structure, but sometimes it's just faster and easier to copy that directory using Finder (or Explorer), and then remove those pesky .svn dirs before "svn add"-attaching that copied directory to the new location.

  4. Krysztof von Murphy Says:

    Just a note to say « thank you ». Notes to oneself are so convenient for lazy people just googling for a problem :-)

Leave a Reply