Reputation: 1565
I have an existing git repository in which I've always been working on. But recently, I'd need to push the commits into svn (no need to include all the merge, but at least a single linear master branch will do)
I'm not very good in git/svn, I'm just a general user that use SourceTree and CornerStone or Tortoise with nice UI to do my commits, branching and tagging. I've used git-svn before to migrate an svn repo into git, but never did the vice versa.
Is it possible? I've googled through several tutorials but none of them work. I'm also not very good with those terms like rebase
, reflog
etc and will be very appreciative if there is some good guide to get the simple things done without needing to learn through the more complex part of git/svn. (Simple as I guess there must be people who're facing the same problem and did it before)
Thanks in advance!
Upvotes: 3
Views: 1428
Reputation: 5306
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
Upvotes: 7