Migration from SVN to Git

How to migrate a repository under Subversion (SVN) to Git?

Author: Paweł Guzewicz

There is an official Inria guide available at Inria GitLab.

We follow here guidelines from Git and Other Systems Migrating to Git (an online book). Please read carefully the entire explanation below before applying the migration.

  1. Commit all the local changes to files that you have been working on until now under your SVN repository (on the top level of the versioning tree, i.e., trunk directory in SVN).
  2. Gather information about your SVN repo.
    1. Get users info.
      • List all the users with the command:
        svn log --xml --quiet | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = /' > users.txt
      • Edit the mappings in users.txt in case when the automatic extraction isn’t perfect. The format of the file (per line) is:
        svn_user = first_name last_name <email_address>

        e.g.,

        jimmysm = James Smith <james.smith@inria.fr>
    2. Check if there are tags.
      • Run the command to list the tags:
        svn ls -v ^/tags
  3. Clone to your local machine the remote SVN repository (e.g., from Inria GForge) into a new local Git repository by running the command:
    git svn clone svn+ssh://gforge_user@scm.gforge.inria.fr/svnroot/project_slug/ --authors-file=users.txt --no-metadata --prefix "" -s new_project_slug

    Warning: this may take a while.

  4. Change directory to your new Git repo:
    cd new_project_slug
  5. Create a new
    .gitignore

    file for the list of exclusion rules for files.

  6. Clean up the local repository: remove useless or obsolete content, and commit these changes to the local Git repo.
  7. If there were some important tags to keep, you can run the command:
    for t in $(git for-each-ref --format='%(refname:short)' refs/remotes/tags); do git tag ${t/tags\//} $t && git branch -D -r $t; done
  8. Create a new remote Git repository (e.g., at Inria GitLab, make sure to create the project under cedar group with non-public access rights unless you have a code license).
  9. Set a new origin for the new local Git repo to point to the new remote Git repo:
    git remote add origin git@gitlab.inria.fr:cedar/new_project_slug.git
  10. Push the local repo to the remote repo:
    git push -u origin --all

    Warning: this may take a while.

  11. If there were tags to import, push them with:
    git push -u origin --tags
  12. Notify all the users concerned by the migration about the new repository.

  13. Ask the old remote repository owner to disable commits. In case of Inria GForge, Inria Helpdesk staff can help with this request: details in the official Inria guide above.

Comments are closed.