Well, it is actually quite simple.. first you need to clone your svn through git, then add the git repo as another remote to it. This will give you two separate HEAD
, that's why you need to git-rebase
your git commits into the git-svn head. There may be conflicts though as svn only has linear commits. This is why you need the various git command to fix all those before you finally git svn dcommit
to push everything into the svn.
Here is the summary:
1. Create a git svn clone tracking svn
git svn clone svn://DEST/repo/projectname/trunk dest
Now we have a git repo that tracks the destination svn landing point for the import operation.
2: Track the git repo we want to import
cd dest
git remote add -f source /path/to/git/source/repo
Now, if you inspect the git history, you'll see a whole series of commits from the original git repo and, disconnected from this, the master HEAD plus a git-svn HEAD pointing to the original (single) svn commit we cloned.
3: Rebase the original git repo onto git-svn
Here's where the secret magic lies. I seems like there are many ways to go from here. This was the only one I found to work. Of course, I tried many ways that failed. Once I found one that worked, I stopped trying. So if there's a better way I'd love to hear it, but this seems to work well.
git rebase --onto remotes/git-svn --root source/master
At this point, I realised that my git history wasn't strictly linear; I had worked on a few machines, so the history of trunk wove arond a bit.
This meant that what I had expected to be a straightforward operation (that's what you'd expect with a SVN hat on) required a few rebase fix-ups along the way:
(
gvim foo # fix merge conflict
git add foo
git rebase --continue
)
# ... rinse and repeat
These were required because branches in the source repo from work on different machines that got merged together to form the "source" trunk line of development didn't flatten into a rebase without a few tweaks.
In general, the conflicts were small and weren't hard to fix.
4: Push up to svn
Now that we've arranged everything above git-svn, it's a simple case of:
git svn dcommit
To push the changes up into svn.
Source: http://goodliffe.blogspot.sg/2011/08/pushing-git-repository-into-existing.html