Search code examples
gitsvngit-svn

Import an SVN repo with a history of renamed trunks into Git


I am trying to convert a Subversion repository to Git. The problem I am facing is how to preserve the full complete history. The SVN repository has quite convoluted history and then git-svn works, it starts only from particular revision, ignoring all earlier history.

More details: I want to import a project which is now located as per std-layout http://svn.../projects/myProject/trunk. However the trunk is not created in SVN as it is now. It was originally created as some custom path like /my_project, then renamed in SVN into myProject/trunk, then several more moves and renames and it has finally ended up with standard layout.

So, if I just import the repo as-is pointing to the SVN project folder I need, the git-svn result starts history from the revision where the standard layout was introduced, ignoring the fact that the projects/myProject/trunk was moved in the repository multiple times earlier.

Technically I need to import a history of an SVN folder if it was moved/copied into the trunk from some other location (outside the trunk) of the same repository.

Does anybody have any ideas how to recover the history from such repository? Maybe somehow use multiple imports, then git grafts, or some other magic? Is there any easy way?


Solution

  • Same problem here, and I have struggled a lot. Finally, inspired by this question, I summarize following steps to achieve the goal.

    1. Clone svn-root-directory with initial layout
    2. git svn reset -r <revision that add layout folders>
    3. In /.git/config, set remote.svn.fetch/branches/tags to corresponding layout
    4. git svn fetch -r <revisions in this layout, A:B(included) > [--ignore- path=branches\/] (Need to delete remote branch reference with same name (if any) in advance, otherwise it skipping the branching step)
    5. Repeat last 2 steps if there is more layout change
    6. Check if all branches history correct gitk -- all