Clearing all SVN folders in Windows or Linux

DeleteSubversion, despite its many competitors with more modern distributed version control technology, is still going strong today due to its robust architecture and large user base.  Although more modern subversion instances use only one “.svn” folder in the root of the checked-out repository, older versions may have a separate “.svn” folder in each individual subfolder in the project.

Usually, the “.svn” folders are hidden and don’t cause much trouble.  There are times, however, when it can be important to entirely remove version control from a project, yet still keep the project files.  For example, this can be useful when merging files from one project to another, or when creating an archive for public distribution.  If the repository contains hundreds of subfolders, this can be quite a challenge to manually clear.

Linux makes this task easy using the built-in tools.  Simply navigate to the root of the project, and execute the following line:

find -name ".svn" | xargs /bin/rm -rf

The find command returns a list of all the subfolders matching “.svn”, and this is then piped to the rm command to recursively delete the directory.  Running rm using the full path will remove the confirmation prompt, and the “rf” arguments will recursively delete any folder contents.

Windows makes this task a little more complicated, yet still doable.  Again, navigate to the root of the project, and execute the following command:

for /r %i in (.svn) do rmdir /s /q "%i"

The “for” loop in this syntax will recursively run the target command in each subdirectory.  Note that the variable is enclosed in double-quote; this will make sure that the command will execute properly even if there is a space in the subfolder name.  Again, rmdir is passed parameters to execute recursively and without prompt.

The problem with the Windows implementation is that the rmdir command is actually executed individually in each folder in the entire directory structure, whether or not a “.svn” subfolder is there.  This should not cause a problem in execution, however it will display many extraneous messages to the screen.

Using these removal techniques, SVN overhead can be completely cleared from a folder.  Again, this can be useful in situations when merging components, upgrading SVN, or even when switching version control systems entirely to Mercurial or Git.

Written by Andrew Palczewski

About the Author
Andrew Palczewski is CEO of apHarmony, a Chicago software development company. He holds a Master's degree in Computer Engineering from the University of Illinois at Urbana-Champaign and has over ten years' experience in managing development of software projects.

RSS Twitter LinkedIn Facebook Email

Leave a Reply

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