How do I migrate an SVN repository with history to a new Git repository?

前端 未结 30 1685
离开以前
离开以前 2020-11-22 02:51

I read the Git manual, FAQ, Git - SVN crash course, etc. and they all explain this and that, but nowhere can you find a simple instruction like:

SVN repository in: <

30条回答
  •  失恋的感觉
    2020-11-22 03:38

    A somewhat extended answer using just git, SVN, and bash. It includes steps for SVN repositories that do not use the conventional layout with a trunk/branches/tags directory layout (SVN does absolutely nothing to enforce this kind of layout).

    First use this bash script to scan your SVN repo for the different people who contributed and to generate a template for a mapping file:

    #!/usr/bin/env bash
    authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
    for author in ${authors}; do
      echo "${author} = NAME ";
    done
    

    Use this to create an authors file where you map svn usernames to usernames and email as set by your developers using git config properties user.name and user.email (note that for a service like GitHub only having a matching email is enough).

    Then have git svn clone the svn repository to a git repository, telling it about the mapping:

    git svn clone --authors-file=authors --stdlayout svn://example.org/Folder/projectroot

    This can take incredibly long, since git svn will individually check out every revision for every tag or branch that exists. (note that tags in SVN are just really branches, so they end up as such in Git). You can speed this up by removing old tags and branches in SVN you don't need.

    Running this on a server in the same network or on the same server can also really speed this up. Also, if for some reason this process gets interrupted you can resume it using

    git svn rebase --continue

    In a lot of cases you're done here. But if your SVN repo has an unconventional layout where you simply have a directory in SVN you want to put in a git branch you can do some extra steps.

    The simplest is to just make a new SVN repo on your server that does follow convention and use svn copy to put your directory in trunk or a branch. This might be the only way if your directory is all the way at the root of the repo, when I last tried this git svn simply refused to do a checkout.

    You can also do this using git. For git svn clone simply use the directory you want to to put in a git branch.

    After run

    git branch --set-upstream master git-svn
    git svn rebase
    

    Note that this required Git 1.7 or higher.

提交回复
热议问题