Search code examples
gitsvnversion-controltortoisesvngit-svn

SVN to Git migration Commit history Issue


I have a badly structured SVN repo. Let me try to give you an image.

svn-repo
|
|--branches
|     |
|     |-- project1
|     |-- project2
|     |-- tragetProject
|               |
|               |-- targetProject5.0.0
|               |-- targetProject5.0.1
|               |-- targetProject5.0.2
|               |-- ...
|
|--trunk
      |
      |-- project1
      |-- project2
      |-- ...

The project I want to migrate is the "targetProject". Each branch is derived from the latest branch, eg. 5.0.1 is a branch from 5.0.0. So each branch in svn has the commit history of it's ancestor.

This is the process I tried in order to migrate to git.

git svn init [trargetProject5.0.2 Url]
git svn fetch

My issue is that although the svn branch has all commit history, after fetch, in git local master there is only the commit history of this branch and not of it's ancestors.

I need to get all history. I tried changing the git branch url in git config in order to fetch the commits for each branch but this also failed as "git svn rebase" did not work as expected. I also need to get new commits of a maybe new branch created in svn repo. Can anybody help or provide me a new way to deal with this? Thanks.


Solution

  • Ok I have found the solution.

    Instead of cloning the trunk of my huge repo I wanted to clone a certain branch. So using this command does the trick.

    git svn clone -T branches/tragetProject/tragetProject5.0.2 http://example.com/PROJECT
    

    This will clone the current branch and also search each parent for all commit history.

    Because my svn repo is huge and all branches are linked together this command would take ages to complete and would fetch unwanted commits from legacy branches. By adding -r<revision>:HEAD at the end you limit the clone investigation to certain revision.

    So the the command becomes:

    git svn clone -T branches/tragetProject/tragetProject5.0.2 http://example.com/PROJECT -r40000:HEAD
    

    Hope this helps someone in the future.

    ref https://gist.github.com/trodrigues/1023167#file-gistfile1-txt-L30