I have an existing git repository with a long history. For business reasons i have to mirror that repository to a svn server. I tried several ways but always failed so far.
2 Answers
I hard time do it some time ago, so I've collected some steps from different sources to do it.This procedure will keep your full git history. Before starting make sure to have a backup copy of your repository.
The first thing to do is create an empty svn
repository. When you're done with it be sure to have git-svn
installed and edit yout .git/config
to track your newly created svn
repos:
[svn-remote "svn"]
url = https://your.svn.repo
fetch = :refs/remotes/git-svn
Now you can fetch your svn
repo:
git svn fetch
You should see the remote branch following your svn
repo, you can check with:
git branch -a
Now get the hash of your root commit
and of the svn
branch:
git rev-list --parents master | grep '^.\{40\}$'
git rev-parse remotes/git-svn
Create the graft:
echo <hash-of-root-commit> <hash-of-svn-branch-commit> >> .git/info/grafts
Now if you use a graphical wrapper for git
(I use tig
) you should see that your root commit
descends from the svn-branch
.
At this point you have to propagate the graft
making it permanent:
git filter-branch -- remotes/git-svn --all
Now we don't need it anymore so we can delete it
rm .git/info/grafts
Check with your graphical git wrapper that the svn-branch
is the master
ancestor.
Now you're almost done, rebase your history on top of trunk:
git svn rebase
Now your ready to commit to your svn
repo using
git svn dcommit
I've created this procedure merging infos I've found here and here, so thanks to the respective authors. I've modified the first part because the proposed procedure didn't worked for me.
Please note that git-svn
approach leads to partial history loss. Consider using SubGit instead, it's able to convert Git repository into SVN keeping the history of all branches.
Below you can find an example of using SubGit in a local mode, i.e. when both Subversion and Git repositories reside on the same host:
$ subgit configure SVN_REPO
# adjust SVN_REPO/conf/subgit.conf, so git.default.repository points to GIT_REPO
# adjust SVN_REPO/conf/authors.txt to map SVN usernames to Git identities
$ subgit install SVN_REPO
$ subgit uninstall --purge SVN_REPO
Once we've converted Linux kernel Git repository to SVN this way. Hope that helps.

- 2,979
- 20
- 28