Converting a Subversion repository to Git

The description is taken from John Albin's blog Converting a Subversion repository to Git.
  1. Checkout the project in a new clean workspace
    % mkdir svn2git
    % cd svn2git
    % svn checkout https://svn.apache.org/repos/asf/db/jdo
        
  2. Retrieve a list of all Subversion committers

    Run the following command that creates the file authors-transform.txt. Then edit authors-transform.txt and add full anme and email on each line.

    % svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
  3. Clone the Subversion repository using git-svn

    The following command will place the git repository in the "~/temp" folder inside your home directory. The command will fail, if there are authors not included in authors-transform.txt. Then you need to extend authors-transform.txt, remove the files being checked out so far and run thecommand again.

    % git svn clone https://svn.apache.org/repos/asf/db/jdo --no-metadata -A authors-transform.txt --stdlayout ~/temp
  4. Convert svn:ignore properties to .gitignore
  5. % cd ~/temp
    % git svn show-ignore > .gitignore
    % git add .gitignore
    % git commit -m 'Convert svn:ignore properties to .gitignore.'
        
  6. Find empty directories

    Git does not handle empty directories. That means they are removed after the migration from svn to git. If they are imporant for emaple for the build process you should create a file (e.g. README.txt) in the directory.

  7. Push repository to a bare git repository

    Create a bare repository

    % git init --bare ~/new-bare.git
    % cd ~/new-bare.git
    % git symbolic-ref HEAD refs/heads/trunk
        

    Then push the temp repository to the new bare repository.

    % cd ~/temp
    % git remote add bare ~/new-bare.git
    % git config remote.bare.push 'refs/remotes/*:refs/heads/*'
    % git push bare
    % rm -rf ~/temp
        
  8. Rename "trunk" branch to "master"
    % cd ~/new-bare.git
    % git branch -m trunk master
        
  9. Clean up branches and tags
    % cd ~/new-bare.git
    % git for-each-ref --format='%(refname)' refs/heads/tags |
    cut -d / -f 4 |
    while read ref
    do
      git tag "$ref" "refs/heads/tags/$ref";
      git branch -D "tags/$ref";
    done
        
  10. Copy Git repo from ~/new-bare.git to remote repository
    % git remote rm origin
    % git remote add origin  https://gitbox.apache.org/repos/asf/db-jdo.git
    % git push --all
    % git push --tags