Search code examples
gitsvngit-svn

I'd like to copy svn project to git with history


I would like to copy svn project to git project on linux environment. Currently I'm having my project in svn repo with branches, tags and trunk folder structure. I need to copy everything to git repo including history. I thought of using svn2git but do not have a good idea on the steps that I need to follow.


Solution

  • svn2git is a great tool. I'm using it to migrate over a large project. You need to define rules for each branch/tags. Wild cards are your friend.

    trunk/A/B
    branches/Foo/A/B
    branches/Bar/A/B
    tags/Baz/A/B
    tags/Foobar/A/B
    

    Here are some sample rules. NOTE: Rules are run in order.

    match /trunk/
      branch master
    end match
    
    match /branches/([^/]+)/
      branch \1
    end match 
    
    match /tags/([^/]+)/
      branch refs/tags/\1
      annotated true
    end match
    

    This will result in the following branches: master, Foo, and Bar and tags Baz and Foobar.

    Something that took me a while to figure out is if you need to dig deeper into the path you need to use the recurse function. For example if a commit copies all of branches into tags, the path would just be /branches/. You need to rule to go down a directory.

    match /branches/$
      action recurse
    end match
    

    Another great tool to use before writing your rules is svneverever. It will help you write your rules.

    https://blog.hartwork.org/posts/before-svn2git-you-want-to-run-svneverever/