Transfering Subversion repositories

Transferring to a new subversion repository

Subversion repositories can be copied using the svnsync command that comes bundled with Subversion.

  1. Initialise the new repository:

    svnsync init NEW_URL OLD_URL

    This may fail if the new repository is not empty, or if the new repository does not allow modification of revision properties. If either of these are the case, contact the administrator of the new repository.

  2. Copy each revision to the new repository.

    svnsync sync NEW_URL OLD_URL

Transferring to a Git repository

Alternatively, a Subversion repository can be converted to a Git repository using git-svn. You may need to install both git and git-svn.

  1. Git uses names and email addresses rather than usernames to identify comitters. Create a file called users.txt that maps the usernames in your Subversion repository to names and email addresses. The file should have the following format:

    jsmith = John Smith <>
    willj = Will Jones <>

    Note: If you have a machine with grep, sort and perl installed, you can use the following command to generate a list of author names:

    svn log ^/ --xml | grep '^<author>' | sort -u | perl -pe 's/<author>(.*?)<\/author>/$1 = /' > users.txt
  2. If the standard trunk, branches, tag layout has been used:

    git svn clone --authors-file=users.txt --stdlayout --prefix=svn/ --no-metadata
  3. If a non-standard layout has been used with other branches or folders these should be cloned individually. For example:

    git svn clone --authors-file=users.txt --prefix=svn/ --no-metadata
  4. Move old SVN tags to be proper Git tags:

    git for-each-ref refs/remotes/svn/tags | cut -d / -f 5- | grep -v @ | while read tagname 
      git tag "$tagname" "svn/tags/$tagname"
      git branch -r -d "svn/tags/$tagname"
  5. Move the rest of the refs under refs/remotes to be local branches:

    git for-each-ref refs/remotes | cut -d / -f 4- | grep -v @ | while read branchname 
      git branch "$branchname" "svn/$branchname"
      git branch -r -d "svn/$branchname"
  6. Add your new git server as a remote and push to it:

    git remote add origin GIT_REPOSITORY_LOCATION
    git push origin --all
    git push origin --tags