Remove .svn Folders from the Project Directory

Subversion stores the state of your working directory in special hidden folders. Each subd-directory of your project will have exactly one hidden folder named .svn containing Subverion meta-data. When you want to archive your code or share it with someone who doesn’t use SVN, you may want to delete them.

Manually removing the .svn folders is tedious – especially if your project is big, and contains many nested subdirectories. Some of my Java projects suffer from this syndrome, as I sometimes tend to create big package hierarchies. I was about to whip out some sort of cleanup script to automate this process, but then I noticed that Jon Galloway already did this. In fact, he took this idea one step further and turned his script into a registry hack that will put a nifty “Delete SVN Folders” directly into your right-click context menu.

If you are to lazy to click the link, here is the registry modification he proposed:

Windows Registry Editor Version 5.00
@="Delete SVN Folders"
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""

This will recursively delete all the .svn folders in the directory on which you run it. Note that Jon is using the cmd shell so you will see a command prompt window pop up on the screen for a few seconds as these files are deleted. You can skip the COLOR statement if you just want to see an ordinary black console – but I thought that the blue one was a nice touch so I left it in place.

Needless to say, this only works on windows. In linux you can simply use find to accomplish the same thing:

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

That or a variation of it. Some people like to put the rm statement first and then put find in “back-ticks”, other people like to pipe the output of find int rm and etc. This method is probably more efficient because we avoid pipes and redirections.

Of course I know that Craig will probably post a loop version of this – but just I like my find statement. :mrgreen:

[tags]subversion, svn, .svn folders, jon galloway, registry hack, registry, cmd, find, bash[/tags]

This entry was posted in sysadmin notes and tagged , . Bookmark the permalink.

8 Responses to Remove .svn Folders from the Project Directory

  1. Stephane FRANCE Mozilla Firefox Debian GNU/Linux says:

    I’d rather use “svn export” to get a fresh copy out of the repository, without the “.svn” directories :-)

    Reply  |  Quote
  2. Luke UNITED STATES Mozilla Firefox Windows says:

    True but but export requires you to pull your code over the network connection. Copying the repository locally and then removing the meta-data folder might be faster and more convenient.

    Also, sometimes your work folder might contain files which would usually not be in the repository, but which you might want to archive or share – like binaries.

    Reply  |  Quote
  3. Stephane FRANCE Mozilla Firefox Debian GNU/Linux says:

    right, but then you’re own working copy is broken and next time you want to work on this project, you have to check it out of repository again … same problem ?

    Then I’d rather use tar to bundle your repository, using the –exclude not to archive the “.svn” directories… No network overhead, plus the extra bonus of making an easy to get, compressed archive… :-) (I feel like selling a hoover :D)

    But alright, the point was to do this on Windows, so your registry hack does the job !

    Reply  |  Quote
  4. Luke UNITED STATES Mozilla Firefox Windows says:

    Yeah, either way is fine. What I wanted to do is to put a zip file with all the code on the project page, in case someone just wants to look at it but doesn’t want to or know how to mess around with SVN.

    So my first instinct was to make a copy of my work directory and delete the .svn files. I could have just exported from SVN but then I would be downloading all the code that I just checked in just so that I can zip it and upload it again.

    Not that my connection is slow, but it just seemed like a pointless waste of bandwidth at the time. ;P

    Reply  |  Quote
  5. Conor SPAIN Safari Mac OS says:

    > True but but export requires you to pull your code over the network

    svn export works on local directories as well “svn export ~/WorkingTrunk ~/CleanTrunk”

    Reply  |  Quote
  6. Samit UNITED STATES Internet Explorer Windows says:

    Simply Press F3 and search for .svn ……
    Just take care of three things:

    1. Tool–Folder Option–View…….Make sure that Show hidden files and folder is true (By selecting the radio button)

    2. While searching, go to Advance Option, and check the first 3 check boxes (1. Search System Folder, 2. Search Hidden files and folder 3. Seacrh subfolder

    3. Press Search and delete the required svn folder.

    Reply  |  Quote
  7. Drew UNITED STATES Mozilla Firefox Windows says:

    Thank you for this!

    I had a problem with SVN not wanting to “update”.
    To fix the problem all the .svn folders needed to be deleted, and export was not an option. Your method saved me hours of deleting folders in a cmd window.

    Thank you again!
    Drew –

    Reply  |  Quote
  8. Allan AUSTRALIA Mozilla Firefox Mac OS says:

    Thanks heaps, was able to use the find and rm command on OSX too. Worked a treat.

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *