Git svn relies heavily on the svn URL. Every commit that is imported from svn has a git-svn-id that includes the svn URL.
A valid relocations strategy is to call git-svn clone on the new repository and merge the changes onto that new close. For a more detailed procedure, see this article:
I cloned using the file:// protocol, and wanted to switch to the http:// protocol.
It is tempting to edit the url setting in the [svn-remote "svn"] section of .git/config, but on its own this does not work. In general you need to follow the following procedure:
Switch the svn-remote url setting to the new name.
Run git svn fetch. This needs to fetch at least one new revision from svn!
Change the svn-remote url setting 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 the svn-remote url setting back to the new URL.
Unfortunately most of the links in these answers aren't working, so I'm going to duplicate a bit of information from the git wiki for future reference.
This solution worked for me:
Edit the svn-remoteurl (or fetch path) in .git/config to point to the new
domain/url/path
Run git git svn fetch. This needs to fetch at least one new revision from svn!
If you attempt git svn rebase now, you'll get an error message like this:
Unable to determine upstream SVN information from working tree history
I think this is because git svn is confused by the fact that your latest commit prior to the fetch will have a git-svn-id pointing to the old path, which doesn't match the one found in .git/config.
As a workaround, change svn-remoteurl (or fetch path) back to the original domain/url/path
Now run git svn rebase -l again to do a local rebase with the changes that came in with the last fetch operation. This time it will work, apparently because git svn won't be confused by the fact that the git-svn-id of the new head doesn't match with that found in .git/config.
Finally, change svn-remoteurl (or fetch path) back to the new domain/url/path
This script, taken from a blog entry, has worked for me. Supply old and new repo URL as parameter, just like for svn switch --relocate.
The script calls git filter-branch to replace Subversion URLs in the git-svn-id in the commit messages, updates .git/config, and also updates git-svn metadata by recreating it using git svn rebase. While git svn clone might be the more robust solution, the filter-branch approach works much faster for huge repositories (hours vs. days).
#!/bin/sh
# Must be called with two command-line args.
# Example: git-svn-relocate.sh http://old.server https://new.server
if [ $# -ne 2 ]
then
echo "Please invoke this script with two command-line arguments (old and new SVN URLs)."
exit $E_NO_ARGS
fi
# Prepare URLs for regex search and replace.
oldUrl=`echo $1 | awk '{gsub("[\\\.]", "\\\\\\\&");print}'`
newUrl=`echo $2 | awk '{gsub("[\\\&]", "\\\\\\\&");print}'`
filter="sed \"s|^git-svn-id: $oldUrl|git-svn-id: $newUrl|g\""
git filter-branch --msg-filter "$filter" -- --all
sed -i.backup -e "s|$oldUrl|$newUrl|g" .git/config
rm -rf .git/svn
git svn rebase
Yet faster than git-filter-branch (i.e., minutes instead of hours), but similar in spirit, is to use git_fast_filter. However, this requires a bit more coding, and no neat ready-packed solution exists. In contrast to git-filter-branch, this will create a new repo from an old one. It is assumed that master points to the last SVN commit.
Clone git_fast_filter from the Gitorious repo.
Create a Python script in the same directory where you cloned git_fast_filter based on this Gist, set the executable bit using chmod +x. Adapt old and new repository paths. (Contents of the script are pasted below, too.)
Initialize a new target repository using git init, change working directory to this new repo.
The above git svn rebase -l solution didn't work for me. I decided to go about it a different way:
Clone old SVN repo into git repo old and new SVN into git repo new
Fetch old into new
cd new
git fetch ../old
git tag old FETCH_HEAD
Rebase new on top of old (should succeed because the trees in the root of new and the tip of old are identical)
git checkout master (Assumes that the master branch is pointing at the SVN head. This will be the case with a clean clone; otherwise dcommit before you start.)
git rebase --root --onto old
Rebuild the git-svn metadata of new to account for the rebase
git update-ref --no-deref refs/remotes/git-svn master (adjust the remote ref depending on how you cloned, e.g. it could be refs/remotes/svn/trunk)
It handles the relocate without checking out another copy, and it even handles the case where there are un-pushed changes in one or more branches (since that breaks the regular logic). It uses stuff from the git filter-branch answer (for the main logic) and the answer about copying branches from one instance of the repo to another (for copying branches with un-pushed changes).
I've been using this to relocate a bunch of git-svn repos that I have for work, and this version of the script (I've been through countless iterations) seems to work for me. It isn't super-fast, but it does seem to handle all of the cases I've encountered and result in a fully-relocated repo.
The script gives you the option to create a copy of the repo before making any changes, so you can use this option to create a backup. Creating a copy is required if you have un-pushed changes in any branches.
The script does not use any gems or other libraries not included in the normal MRI Ruby installation. It does use the readline and fileutils libraries included in MRI.
Hopefully my script will prove useful to someone else. Feel free to make changes to the script.
NOTE: I've only tested this script with git 2.3.0/2.3.1 and Ruby 2.2.0 on OS X 10.10 Yosemite (since that's the environment I use), but I would expect it to work on other environments as well. No guarantees about Windows, though.