Restoring deleted trunk or branch in Subversion

If you ever accidentally delete a branch (or even the trunk) or any other directory in Subversion  don’t panic it can be restored.

The Subversion book mentions a technique with checking out the current version and reverse merging the change in “Undoing Changes”. But this is very slow for really big repositories and it’s a bit complicated – I thought there should be an easier way and in fact, there is.

svn copy  {repoUrl}/trunk@{repoVersionBeforeDelete} {repoUrl}/trunk

E.g. if you deleted trunk in your repo http://myhost/svn in commit 1234 (so the last version with existing trunk was 1233) you restore your trunk with:

svn copy http://myhost/svn@1233 http://myhost/svn

Voila – that’s it: your trunk is ready for new commits.