Archive for the 'Subversion' Category

How to remove all .svn subdirs from a given directory

Wednesday, April 18th, 2007

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

rm -rf `find . -type -d -name ".svn"`

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.