Recovering deleted branches in Subversion

If, like me, you delete a branch in Subversion (SVN) that later on you realise you actually still need, you don’t need to panic.

In my case, I deleted a couple of feature branches I thought had been merged into the release candidate but hadn’t.  Thanks to my friend and colleague Damian, I managed to get them back without waiting for hours of checking out the parent folder full of other feature branches.  Here’s how I did it using TortoiseSVN:

  1. Perform a sparse checkout of HEAD revision of the folder that used to contain your branch(es).  I.e. for svn:// you should checkout svn://  To make it sparse, in the Checkout Dialog you should select “Immediate children, including folders” from the Checkout Depth dropdown.
  2. Use the Revision Log to find the revision immediately before the one where you deleted the branch.  Repeat step 1, but instead of HEAD, sparse checkout that revision.  For this example let’s call it revision 1024 because that’s a nice round number.
  3. In Windows Explorer you should now have two sparse working copies for same URL but different revisions.  One will contain the deleted branch (r1024), the other will not (HEAD).
  4. Right-click and drag the folders representing the branches you want back from the r1024 working copy to the HEAD one. You’ll get a context menu, from which you should choose SVN Copy Versioned Item(s) Here.
  5. Now commit the HEAD working copy and review in the Repository Browser.  All should be well!

Thanks again to Damian for sorting this out!