9

I have an existing SVN repo and I would like to import a part of it, with history into an existing Git repo. Could anyone give me a high-level overview of the commands needed to do this?

Summary:

  • I want to move some subdirectories in an existing SVN repository (but not the rest of the repo)
  • I have an existing Git repo that I want to import those directories into
  • I want to preserve the history of just the subdirectories I moved (but not anything else)

I have a feeling this involves something with git filter-branch and some strange merges. Any help would be appreciated.

Andrew Mao
  • 35,740
  • 23
  • 143
  • 224
  • 1
    I suspect it might be easier to import the full repository, then use `git filter-branch` to prune out the stuff you don't want to keep. I'm not sure it's even possible to only import part of an `svn` repository in that way, and even if you can it's not likely to be simple... – twalberg Jan 21 '13 at 20:41
  • 1
    You can dump the Subversion repository using `svnadmin dump`, and then use [`svndumpfilter`](http://svnbook.red-bean.com/en/1.7/svn.ref.svndumpfilter.html) to filter out the parts you don't want. – David W. Jan 21 '13 at 20:56

1 Answers1

12

It turns out to be pretty complicated, but here's what I did.

  1. Prepare the SVN repository first. I was going to delete the files from SVN afterward, so it helped to put all the files in one directory (this also makes filter-branch easier later.)

  2. Checked out the SVN repo using git: git svn clone http://path/to/svnrepo. This creates a git version of the svn repo.

  3. Using the ideas from this SO post, Detach (move) subdirectory into separate Git repository, I used the filter-branch --subdirectory-filter to filter the directory that I wanted, and to remove history of other stuff from SVN that I did not want to keep in git. You can also use git subtree, a new feature, as in Howto extract a git subdirectory and make a submodule out of it?

  4. Then, using the ideas from this SO post, How do you merge two Git repositories?, I imported the new git repo into the parent project that I wanted to add it to. The accepted answer is incorrect, check out the other answers on that page; you want to do a git remote add git-proj <path> followed by a git pull.

  5. Finally, push the changes to the git project.

Community
  • 1
  • 1
Andrew Mao
  • 35,740
  • 23
  • 143
  • 224
  • worked for me but with git merge --allow-unrelated-histories origin/master to merge the repositories (found from here https://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories) – James Hamilton Jun 22 '17 at 09:16