51

I needed to rename a SVN branch, so I did:

$ svn move https://server/repos/myrepo/branches/oldbranch \
    https://server/repos/myrepo/branches/newbranch

So far, so good -- the branch has been renamed.

The trouble is, we have existing sandboxes checked out from this branch and when I try to update I get this error:

$ svn update
svn: Target path '/branches/oldbranch' does not exist

A fairly self-explanatory error. After a quick search I thought I had found the solution: Relocating SVN working copy following branch rename

The trouble is, that when I try to issue that command I get another error:

$ svn switch --relocate https://server/repos/myrepo/branches/oldbranch \
    https://server/repos/myrepo/branches/newbranch
svn: Relocate can only change the repository part of an URL

As far as I can see, I am using the --relocate command the same way as Sander Rijken. Any ideas why I get this error?

Community
  • 1
  • 1
Lee Netherton
  • 21,347
  • 12
  • 68
  • 102

3 Answers3

58

Just do

svn switch https://server/repos/myrepo/branches/newbranch

from within your working copy.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks, this works, but it does delete all of the unversioned files from the sandbox when I next do an `svn update`... something I was hoping to avoid. – Lee Netherton Feb 24 '11 at 10:30
  • 2
    `From within your working copy` => you mean "`cd [oldbranch]` first then, from there, type the command `svn switch [...]`? – Olivier Pons Apr 25 '13 at 13:45
  • 1
    I realize @OlivierPons's question is 7 years old, but since nobody confirmed - for the sake of future visitors here, yes - you would do `cd oldbranch` then `svn switch ^/branches/newbranch` (note that the ^ tells svn that you're switching relative to the current branch's root path.) – DevDaddyNick Apr 28 '20 at 20:24
5

For changing relative path you must to use pure svn switch (and anyway switch --relocate is deprecated), as written in svn help switch for 1-st form

switch URL[@PEGREV] [PATH] Update the working copy to mirror a new URL within the repository.

 This behavior is similar to 'svn update', and is the way to
 move a working copy to a branch or tag within the same repository.

I.e in the root of WC for oldbranch, which is now newbranch, you have to use

svn switch ^/branches/newbranch

Community
  • 1
  • 1
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
3

If you had simply wanted to rename a SVN branch in Eclipse, the easiest would have been to go into the SVN Repository Exploring Perspective, and then right click on your branch -> Refactor-> Rename

galeop
  • 1,685
  • 14
  • 13