10

I have the daunting task of merging a site with a ton of files between two teams. One team has been working on git and one using svn. Can I please get some help with the best way to go about this? What I am thinking is I will create a new bare repo

git clone --bare ~/dir gitversion.git

Then create a branch from there

git checkout -b import-svn

Then on that branch I will pull from svn

svn checkout svn://svnversion/trunk

Now on this branch I would rebase?

git rebase origin/master

Then switch back to master branch

git merge import-svn

I tried something like this but seemed to be getting nowhere. Never got any merge conflicts or anything which doesnt make sense. Can someone please show me a decent workflow to accomplish this?

Zac
  • 12,637
  • 21
  • 74
  • 122
  • are they completely unrelated, or do they share some content? – CharlesB Apr 24 '12 at 23:05
  • Will there be any more work done in SVN? If so, what will the ongoing workflow between the two be? – Ryan Stewart Apr 24 '12 at 23:06
  • also will the final repo be svn or git? – CharlesB Apr 24 '12 at 23:07
  • They are almost identical sites.. just two teams working on different stuff. @Ryan and Charles I wish I knew the answer to that other question. I think we are moving to git but right now it is still up in the air. I basically just need to get this one merge together and then will just continue with the assumption we are using git. – Zac Apr 24 '12 at 23:09
  • almost identical/different stuff?? you say 2 different things here... – CharlesB Apr 24 '12 at 23:11
  • sorry for being confusing... it is the same site. I am not sure exactly what files each team has been working on but there is probably some overlap. – Zac Apr 24 '12 at 23:12
  • two teams working on the same site but with different repos? what kind of company is this??? – CharlesB Apr 24 '12 at 23:17
  • 1
    ha! dont ask.. a highly disorganized one. welcome to my hell. – Zac Apr 24 '12 at 23:20

3 Answers3

9

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
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • cool thank you! this seems a good strategy. i will try it out. – Zac Apr 24 '12 at 23:31
  • 1
    note that this doesn't preserve history from the SVN repo, which may be desirable – CharlesB Apr 24 '12 at 23:32
  • Actually doesn't preserve history in either original SVN or GIT – GoZoner Apr 24 '12 at 23:34
  • thats ok about the history... i just want to get this into one repo. thanks for your help, i will let you know how it goes. – Zac Apr 24 '12 at 23:51
  • Whew.. that was painful. I think I got it though. Thanks again for your help, your walkthrough was immensely helpful. – Zac Apr 25 '12 at 04:33
1

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.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
1

There is a recent article on the topic by Microsoft including a walk through using the git-svn utility. They provide information on merging with and without svn change history.

c-type
  • 51
  • 2