Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing an SVN Repo into an EXISTING Git repo as a branch

Tags:

git

svn

git-svn

I've currently got a project on google code that I'd like to incorporate into a project on Github.

The issue is that the SVN project is essentially just a folder of the larger project on github, so I don't think i can just use git-svn for this.

I'm assuming I can use git svn to clone the project, but then i'm not sure how to graft the svn project onto the existing git project properly.

The desired outcome would be to get the SVN history into a Git branch (not graft it onto master).

Being able to dcommit back to svn isn't really necessary (if that helps).

SOLVED

I ended up using just_doug's suggestion, but with some minor modifications:

1: I used the suggestions from http://ivanz.com/2009/01/15/selective-import-of-svn-branches-into-a-gitgit-svn-repository/ to add googlecode as a remote ref

2: I create a new branch off of master for the remote branch i wanted

3: I used

git merge -s ours --no-commit googlecode-remote

to merge the two

4: I then used

git read-tree --prefix=folder1/folder2/ -u googlecode-remote

to read in the merge history and rebase to the desired subfolder

hopefully this helps someone in a similar situation ;)

like image 234
Alex B. Avatar asked Nov 05 '22 00:11

Alex B.


1 Answers

I haven't used it before, but it sounds like you want the subtree merge strategy. This article has some more detail on how to use it.

Basically, you add the SVN repository as a remote, then use the git read-tree command to "graft" it in as a subdirectory of your pure git repository. Depending on how you want the histories to show up, you can either do git merge -s subtree to merge it into your pure-git branch (git-svn commits preserved) or you can follow the steps in the second link and add the --squash and --no-commit flags and have the merge show up as a single commit in the pure-git branch.

The instructions assume that the remote is also a git repo. If the local repo was created with git instead of git-svn, not sure how well it will play out. It's kind of a kludge, but here are some scripts for making an intermediate repository that just mirrors an SVN repo in git. This way, you could make a git-svn mirror of the svn repo, and add this as a remote and the instructions above should work as described.

like image 90
just_doug Avatar answered Nov 09 '22 12:11

just_doug