Search code examples
gitsvnversion-controlgit-svn

How to migrate part of an SVN repo with history to a new Git repository?


I need to migrate part of an SVN repo to git.

For example, the SVN root is: http://example.com/svn/project and I need to migrate a project subdirectory like http://example.com/svn/project/trunk/foo/bare.

I tried to use:

git svn clone http://example.com/svn/project \
    -Ttrunk/foo/bare --no-metadata -A ~/authors-transform.txt ~/temp

After this command I get a git repo with two branches: trunk and trunk@61, but I need only one branch.

What do I need to do to get only one branch after migrating?


Solution

  • Delete the branch that you don't need, of course. But you'll loose the history before revision 61.

    The trunk@61 exists because the directory you are importing was replaced. In a way that git svn does not see as continuation of history. Therefore it recorded the value of the ref at that revision and started again.

    Since it's a one-off conversion, you can use graft to connect the history, filter-branch to rewrite it, so the graft file is not needed (see filter-branch documentation) and than delete the now useless branch.