Wednesday, March 17, 2010

HowTo: Remove recursively all the ".svn" from a directory

Most of the times when you are working on a project you need to collaborate with other people, or you want at least that if your computer crashes not to loose all your work.
In this case it is essential to work with some sort of version control system. Nowadays the most important versioning systems are CVS, SVN and GIT.

In my case the choice is most of the times subversion(SVN) because of its simpleness, its seamless integration into the Eclipse framework due to "SubClipse" and because there are thousands of free SVN-hosts around, of which Google Code is probably the most well known.

This works (more or less) fine and should not be the topic of this post. The problem starts when you want to give your work away without disconnecting from your repository. If you just copy your project and (zip it and) send it to someone else you'll probably send all the ".svn" staff hidden into each folder of your project, and in a reasonably big project this could be even more than 100, which makes it unfeasible to do this work by hand.

For all the Unix users, like the Linux guys and the Mac guys, there is a really simple solution using the terminal. The following command finds recursively all the ".svn"'s in the subtree you are launching the command including "." (Find, starting from "." all directories who's name is ".svn")
find . -type d -name .svn
this command can now be passed to the remove command (rm)
rm -rf `find . -type d -name .svn`
The flags in this case tell to the "rm" command
  • -r --> recursively (all the sub(folders|files))
  • -f --> force (do not ask for confirmation, just delete)

If you are not an experienced Unix user be careful with the "rm" command in combination with these two flags, they could remove your entire system when used in the "right" way :-P

No comments: