I have a number of git projects created as clones of SVN repositories using git-svn. We have migrated our SVN repositories to a new provider so the URL has now changed. How can I update the remote SVN URL of my git clone?
One possibility is that I re-clone from the new SVN repository but I'd prefer not to do that as the process can take days when pulling in the entire history.
Another way to put this question would be, where does git store information about the location of the remote SVN repository you're working with? I.e. where does the URL information come from when you type 'git svn info'?
I found a page in the git wiki which answers exactly my question:
https://git.wiki.kernel.org/index.php/GitSvnSwitch
- Edit the svn-remote url URL in .git/config to point to the new domain name
- Run git svn fetch - This needs to fetch at least one new revision from svn!
- Change svn-remote url back to the original url
- Run git svn rebase -l to do a local rebase (with the changes that came in with the last fetch operation)
- Change svn-remote url back to the new url
- Run git svn rebase should now work again!
This will only work, if the git svn fetch step actually fetches anything! (Took me a while to discover that... I had to put in a dummy revision to our svn repository to make it happen!)
Following the same url [1], but with an updated solution, it becomes much easier.
Inside .git/config
, in the [svn-remote]
section, set url
to the new URL, and set rewriteRoot
to the old URL:
[svn-remote "svn"] url = https://new.svn-server.net/svn/root rewriteRoot = https://old.svn-server.net/svn/root
The same can be surely done via the git config ...
commands from the guide:
$ git config --local --replace-all svn-remote.<name>.rewriteRoot `git config --local --get svn-remote.<name>.url` $ git config --local --replace-all svn-remote.<name>.url <new_url>
Then it just works, for me I don't have to make any dummy revision even though there's no new revisions on the new server. Interestingly, git svn info
reports the same old URL, but with the new URL as Repository Root:
$ git svn info Path: . URL: <old-url> Repository Root: <new-url>
[1] https://git.wiki.kernel.org/index.php/GitSvnSwitch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With