views:

760

answers:

3

Crap. I have two working copies of a subversion repository, one of the trunk, and one of a branch I created. Then, I accidentally the 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? Any help is much appreciated. :-\

+4  A: 

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

John Weldon
didn't seem to work, I am using svn+ssh because it's on a local server, so I tried svn cp svn+ssh://username@serverip/svn/branches/branch-name@9999 svn:ssh://username@serverip/svn/branches/branch-name and I got "Path 'svn+ssh://username@serverip/svn/branches/branch@9999' does not exist in revision 9998"
Luke
what was the revision # that you deleted the branch in? You have to specify that version minus 1...
John Weldon
yeah, sorry, I wrote that backwards, swap the 9999 and 9998
Luke
hmm, I wonder if it has to do with the double @ sign?
John Weldon
what do you mean, because of the username in the url?
Luke
can you try svn cp -r 9998 svn+ssh://username@serverip/svn/branches/branch-name svn+ssh://username@serverip/svn/branches/branch-new-name?
John Weldon
sweet, that worked, thanks a ton!
Luke
cool :) Thanks.
John Weldon
A: 

Hmm... you would have to create another branch off the revision of the original branch just prior to having been deleted. Then physically copy any changes in your orphan working copy to the newly-created branch.

I'm afraid there's no such thing as "undoing" anything in Subversion.

Dmitry Brant
This is correct, why the downvote?
John Weldon
I didn't down-vote, but I guess it's because there _is_ such a thing as "undoing". Being able to undo is one of the main reasons for using a VCS, after all.
sbi
I beg to differ. Any action performed in SVN creates a new revision, whether it's deleting or restoring. You can revert the "state" of a certain branch to a previous revision, but when you commit, you're still committing on top of all the previous changes, including deletes.A true "undo" would have the effect of wiping out the head revision from existence, and making the previous revision become the head. This cannot be done.
Dmitry Brant
@Dimitry: That both the "doing" and the "undoing" are logged and can also be undone doesn't mean it's not undoing. I now can see what you mean, but, in itself, your answer seems wrong to me.
sbi
+3  A: 

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/

Edit: Elsewhere on StackOverflow: http://stackoverflow.com/questions/248821/undoing-a-commit-in-tortoisesvn

leonm
+1 for another way to do the same thing.
John Weldon
this doesn't seem to work either. I get the error that the path /branches/branch-name doesn't exist in revision 108, where 108 is the revision after I deleted the branch
Luke
ok. You'll probably have to checkout /branches. Is your branches very big or is it workable?
leonm