Merge svn repo with git repo

Assuming final repo will be Git. This solution preserves history on both

First work on a non-bare repositories, it's easier for what you want to do. Clone the git repo, and create another git repo from the SVN one with svn2git.

So you have two repos. Add one repo as remote to the other, and import the history into a separate branch :

git remote add ../other-repo
git fetch other-repo
git branch other-repo other-repo/master

You will get a warning that there's no base commit, so you'll have two orphan branches

Now you can merge branches. This should be terrible, awful, since they are related but completely different history, but then you have no other option. Rebase would be nonsense here since commits are unrelated.


I've faced something similar to deal with multiple releases from a SVN-based development. Here is a sketch of how I'd handle it:

# checkout the SVN source
$ svn checkout svn://svnversion/trunk
$ cd /into/svn/checkout

$ git init
$ echo ".svn/" > .gitignore
$ git add .gitignore; git commit -m 'Initial .gitignore'

# Now you have a master branch; create your import-svn branch
$ git checkout -b import-svn

# Add *everything* from the SVN checkout
$ git add -A
$ git commit -m 'Initial SVN'

# Now get the GIT developed stuff
$ git checkout -b import-git master
$ git remote add original-git /path/to/git-developed-repository
$ git pull original-git master         # or whatever branch your git developers used.

# Now you've got two branches 'import-svn' and 'import-git'; DIFF and MERGE as you please

# You don't need the remote anymore.
$ git remote rm original-git

I think that is about right.

Now you can think about merging. Something like the following would work if you considered the 'import-git' as the preferred baseline.

$ git checkout -b git-merge-svn import-git
$ git diff --name-status import-svn
$ git merge import-svn

You could also try a rebase like follows and then decide which you prefer:

$ git checkout -b git-rebase-svn import-git
$ git rebase import-svn

And compare the merge and rebase (should be identical, but you never know..)

$ git diff git-rebase-svn..git-merge-svn

Tags:

Svn

Git