It is inevitable that at some point in time the server hosting your Subversion (SVN) repo is going to change IP address or even URL. Of course when that happens, any SVN working copy check outs will instantly be rendered useless, moaning at the slightest touch of being ‘Unable to connect to a repository at URL…’. Obviously this makes sense because when you checked out your SVN repo you pointed it at a particular URL – with that URL now changed, you need to change your working copy details accordingly. Now obviously one solution is to just trash everything and do a fresh check out from the new SVN server URL, but needless to say, this is a bit overkill don’t you think? – especially with the existence of the svn relocate command!

Then Subversion ‘svn relocate’ command “rewrites” the targeted working copy’s administrative metadata to refer to the new repository location. Two usage syntax cases are catered for:

svn relocate FROM-PREFIX TO-PREFIX [PATH...]
svn relocate TO-URL [PATH] 

The first svn relocate syntax allows you to update one or more working copies by what essentially amounts to a find-and-replace within the repository root URLs recorded in those working copies. Subversion will replace the initial substring FROM-PREFIX with the string TO-PREFIX in those URLs. These initial URL substrings can be as long or as short as is necessary to differentiate between them. Obviously, to use this syntax form, you need to know both the current root URL of the repository to which the working copy is pointing, and the new URL of that repository. (You can use svn info to determine the former.)

The second syntax does not require that you know the current repository root URL with which the working copy is associated at all – only the new repository URL (TO-URL) to which it should be pointing. In this syntax form, only one working copy may be relocated at a time.

The two options in practice:

svn relocate http https
svn relocate

It is important to remember that this type of relocation affects working copy metadata only. It will not change your versioned or unversioned file contents, perform any version control operations (such as commits or updates), and so on.

Bonus: Also, if you are getting a little confused as to when svn switch or svn relocate applies, the rule of thumb is as follows:

  • If the working copy needs to reflect a new directory within the repository, use svn switch.
  • If the working copy still reflects the same repository directory, but the location of the repository itself has changed, use svn relocate.

lego postman and his bicycle

NOTE:¬†Worth noting that if your version of subversion doesn’t support the relocate command, then you can fall back and use svn switch –relocate.

Related Link: