Recovering from subversion corruption or accidentally deleted folders

Subversion is great and very handy but it can be a real pain on the rare occassions that it goes wrong.

Lets say you have accidentally deleted a folder structure (including the .svn folders) or a .svn entry has become corrupt.

How do you get back to work?

Lets demonstrate this step by step:

create a test project to demonstrate and recover using your subversion server. I use springloops and created a project called test there.

Create some simple test content for the project:

~/tmp $ cd /tmp
/tmp $ mkdir test
/tmp $ mkdir -p test/a/b/c
/tmp $ touch test/a/f1.txt
/tmp $ touch test/a/b/f2.txt
/tmp $ touch test/a/b/c/f3.txt
/tmp $ ls -1R test




Import it into our project (substitute your own repository URL):

/tmp $ cd test
/tmp/test $ svn import
Adding         a
Adding         a/b
Adding         a/b/c
Adding         a/b/c/f3.txt
Adding         a/b/f2.txt
Adding         a/f1.txt

Ditch the source and create a working copy to use:

/tmp $ rm -r test
/tmp $ svn checkout test
A    test/a
A    test/a/b
A    test/a/b/c
A    test/a/b/c/f3.txt
A    test/a/b/f2.txt
A    test/a/f1.txt
Checked out revision 1.

"Accidentally" remove test/a/b

/tmp $ sudo rm -r test/a/b

Without sudo here you'll get write protect warnings but you can say yes and they'll get deleted so sudo just saves a bit of typing.

Now our working copy is borked.

/tmp $ cd test
/tmp/test $ svn status
!       a/b

Update will bring it back:

/tmp/test $ svn update .
A    a/b
A    a/b/c
A    a/b/c/f3.txt
A    a/b/f2.txt
Updated to revision 1.
/tmp/test $ svn status
/tmp/test $ 

You can apply this repair anywhere within your project structure to minimise long downloads of files you already have.

If your problem is a corrupt .svn delete the relevant folder using rm as above and apply this repair.

If you have changed files you need to subsequently add back to subversion, copy them somewhere and then copy them back over the repaired files once you've carried out the repair.

Make sure you do not copy back any .svn folders if copying a structure. This is best sorted when you make your file copy:

/tmp/my_backup $ find . -name ".svn" -type d -exec sudo rm -r {} \;

If the commands above don't make sense, stop working in Windows and get yourself a decent (and free!) development environment.


There are currently no comments

New Comment


required (not published)


Australia: 07 3103 2894

International: +61 410 545 357