Need to restore a deleted branch in Subversion

2019-01-21 05:26发布

问题:

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?

回答1:

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...



回答2:

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.


回答3:

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: Undoing a commit in TortoiseSVN



回答4:

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.



回答5:

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



回答6:

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"


回答7:

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