The Blog

Thoughts on building web apps, businesses, and virtual teams.

12 Mar How to clean .svn folders from your project ← Go back

Posted by Alexander Kleshchevnikov on March 12, 2008 — 16 Comments

If you use Subversion to manage your projects you probably have noticed hidden .svn folders in your checked out projects. A Subversion client creates them to store any information about the project’s local state. It’s not a problem until you need to publish your project on the server or share it somewhere.

Why copy unnecessary .svn folders on the server? They can contain lots of data that you do not need and the project will be a bigger size. Of course you can use file manager and remove them all manually, but there is a better idea…

If you are a windows user there is a very nice solution that I found on Jon Galloway’s blog:

  1. Create a file with .reg extension and the following content (or download one that I’ve created):
    @="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" ""
  2. Run the file in the previous step. It will add “Delete SVN Folder” in context menu for all folders.

For Mac users there are powerful bash scripts. We will create one for this purpose.

  1. Create file “remove_svn” in /usr/bin with the following content:
    echo "Remove SVN folders from"
    rm –rf `find . –type d –name .svn`
  2. Change permissions to allow other users to execute it:
    chmod 755 /usr/bin/remove_svn
  3. Change the current directory to the project you want to clean:
    cd [path_to_project]
  4. Run command:

Please notice that these actions will remove information that the Subversion client needs to manage your project. So do not do it with a working copy. To get a clean copy you need to copy the project folder to another location and clean it there.

And finally, there is a second method to get a clean copy of your project – using “svn export” command. More details about it you can find in the book Version Control with Subversion.


1 Trackbacks/Pingbacks

  1. Pingback: Stanislav Stankov » Blog Archive » svn cleanup - on November 27, 2010

Guys, there is “svn export”! Why would you do “svn co” and then remove .svn directories?

Alexey Kovyrin — March 12, 2008, 10:44 pm

because svn export is different than this solution. svn export copy files according to repository, so all changes which are not commited are lost during svn export.

msznapka — March 13, 2008, 3:57 am

@Alexey Kovyrin

Yeah it’s “svn” not “git”. You have to be extremely careful when you commit your changes to the repository because it’s almost a one-way ticket…

Gregory — March 13, 2008, 4:48 am

A project can be big and getting the files by svn export requires time. The described approach is fast and simple (in windows it’s one click at all). Plus, sometimes you need a clean copy of your local version not that which is in the repository.

Alex Kleshchevnikov — March 13, 2008, 7:57 am

On unix-like systems (including Macs), it is possible to have too many arguments for a command line — your

rm -rf `find . -type d -name ‘.svn’`

can fail as a result. A better solution is to use xargs, which has the advantage that your solution has over

find . -type d -name ‘.svn’ -exec rm -rf {} ;

in that it doesn’t spawn a rm for each directory, but also won’t fail because the commandline is too large. xargs handles splitting the arguments from stdin to run the command an optimized number of times.

So, with xargs it looks like:

find . -type d -name ‘.svn’ | xargs rm -rf

Matt Williams — March 13, 2008, 9:53 am

Thanks, Matt! Good point.

Alex Kleshchevnikov — March 13, 2008, 4:04 pm

… with ruby script :)

require 'find'
require 'fileutils'
Find.find('./') do |path|
if File.basename(path) == '.svn'
FileUtils.remove_dir(path, true)

Tomasz BÄ…k — March 13, 2008, 5:33 pm

Definitely useful, when some reason someone breaks his svn copy. Which I guess, almost everyone? lol. On rails, i do that everytime on vendor/plugins

j4s0n — March 14, 2008, 8:10 pm

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.

Samit katiyar — August 19, 2008, 7:54 am

How to remove multiple folders created in svn.

shailender — February 2, 2009, 1:01 am

What do you mean “multiple folders”? This approach deletes all .svn folders.

Alexander Kleshchevnikov — February 2, 2009, 9:25 am

You could also use my tiny tool “PurgeSVN” to delete all those .svn folders.

Stefan — March 22, 2009, 1:36 pm

Working link: PurgeSVN

Stefan — March 22, 2009, 1:37 pm

Thanks for the find command.

I used “find . -type d -name .svn | xargs rm -Rf” which worked fine.

James Tan — April 18, 2010, 12:04 am

those single quotes didn’t come out right for me (they weren’t anything I could type on my keyboard). I got rid of them and it worked

find . -type d -name .svn | xargs rm -rf

Si Li — March 16, 2011, 3:19 pm

Write a comment

* required
* required

← Go back

Get in Touch

Wildbit, LLC

Work 225 Chestnut Street
Philadelphia, PA 19106 USA

Google Maps
+1 (267) 200 0835