Need to restore a deleted branch in Subversion

SvnVersion ControlBranch

Svn Problem Overview


I have two working copies of a Subversion repository, one of the trunk, and one of a branch I created.

I accidentally deleted the branch in a repository browser. How do I restore the branch? Is there a way to undo the most recent commit for the whole repository?

Svn Solutions


Solution 1 - Svn

Here is a solution if you are using TortoiseSVN:

  1. In the repo browser, navigate to the parent folder of the folder you deleted (e.g. "branches").
  2. Right click on the folder and do a "Show Log."
  3. Find the revision where you deleted the specific branch folder.
  4. Select the revision immediately before that revision.
  5. Right click and choose "Browse Repository." You are now looking at the state of the repository at the point in time right before you deleted the branch.
  6. Find the branch folder that you deleted, select, right-click, and choose "Copy to..."
  7. You can now copy the deleted folder to either a new name or even the same name.

Solution 2 - Svn

Use:

svn cp [path to deleted branch]@[revision before delete] [new path]

For example:

svn cp svn://myrepo.com/svn/branches/2.0.5@1993 \
       svn://myrepo.com/svn/branches/2.0.5_restored

Where 1993 is the revision before the delete...

Here is some good documentation...

There must be some way of escaping the @ symbol in the username...

Solution 3 - Svn

Assuming your last revision was 108:

svn merge --revision 108:107
svn diff 
svn commit -m "Reverted revision 108"

You can also add your source URL to the merge:

svn merge --revision 108:107 http://svn/repo/

Elsewhere on Stack Overflow: https://stackoverflow.com/questions/248821/undoing-a-commit-in-tortoisesvn

Solution 4 - Svn

I ran into this problem, but the above command didn't work for me. What did was much easier. I checked out the branch at one revision before I removed it.

The revision that was removed was 9331. I checked it out at 9330:

svn co https://svn.acme.com/svn/giantFlySwatterTargetingSystem/branches/bug1234@9330 restored

That was the easy solution I wanted.

Solution 5 - Svn

This worked for me,

> svn cp --username your_user_name > https://path_to_your_repo/branches/deleted_branch_name@last_revision_before_deletion > https://path_to_your_repo/branches/new_name_for_branch

Solution 6 - Svn

Alternatively, if it was a single commit that deleted the branch:

Revert the commit and then commit

svn merge -c -REV .
svn commit -m "Reverting deletion of branch XYZ"

Solution 7 - Svn

I ran into the same problem and solved it this way in SmartSVN (Enterprise 6.0.2):

  • Open a view on the trunk/HEAD
  • Call menu Repository / Open in Repository Browser (the deleted branch is absent from the branches folder)
  • In the repository browser, call menu Repository / Show Revision...
  • Select the revision just before the deletion (the deleted branch reappears in the branches folder)
  • Right-click on the deleted branch, select Copy in the menu and enter the same path for the destination

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukeView Question on Stackoverflow
Solution 1 - SvnBrian NealView Answer on Stackoverflow
Solution 2 - SvnJohn WeldonView Answer on Stackoverflow
Solution 3 - SvnleonmView Answer on Stackoverflow
Solution 4 - SvnAlan B. DeeView Answer on Stackoverflow
Solution 5 - SvnSibin John MattappallilView Answer on Stackoverflow
Solution 6 - SvnBatteryBackupUnitView Answer on Stackoverflow
Solution 7 - SvnJean-Xavier BardantView Answer on Stackoverflow