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://svn.mycompany.com/branches/features/case4321 you should checkout svn://svn.mycompany.com/branches/features.  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!

Advertisements

6 thoughts on “Recovering deleted branches in Subversion

  1. U save my day. But, i noticed the 4th Step is reversed.

    Right-click and drag the folders representing the branches you want back from the HEAD working copy to the r1024 one. You’ll get a context menu, from which you should choose SVN Copy Versioned Item(s) Here.

    should be

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s