SVN to Git

Converting a SVN Repository to Git

  1. Make sure you have read permissions to the to be converted SVN repository, see https://wiki.its.bfh.ch/doku.php?id=subversion.

  2. Clone existing svn repo:

    git svn clone --username=${USER} https://svn.bfh.ch/repos/${REPO}
    
  3. Prepare authors file:

    cd ${REPO} &&
    
    git log | awk '/^Author: / { print $2 }' | sort -u > ../${REPO}-authors &&
    
    cd ..
    
  4. Manually complete authors file with entries like this:

    bad9 = Daniel Baumann <daniel.baumann@bfh.ch>
    
  5. Clone existing svn repo again:

    git svn clone --authors-file ${REPO}-authors --localtime --no-metadata --preserve-empty-dirs --username=${USER} https://svn.bfh.ch/repos/${REPO} ${REPO}-git
    

Note

Depending on the repository history, you might not want to use --preserve-empty-dirs

  1. Convert svn ignore to git ignore:

    cd ${REPO}-git &&
    
    git svn show-ignore > .gitignore &&
    
    git add .gitignore &&
    
    git commit -a -s -S -m "Converting svn:ignore properties to .gitignore." &&
    
    cd ..
    
  2. Create a new Git repository on git.bfh.ch:

    ssh git@git.bfh.ch create staff/${USER}/${REPO}
    
  3. Upload converted repository to git.bfh.ch:

    git remote add origin git@git.bfh.ch:staff/${USER}/${REPO}.git && git push --all
    
  4. Login to git.bfh.ch and change set the creator to the user you have migrated the repository for:

    /srv/git.bfh.ch/git/staff/${USER}/${REPO}/gl-creator
    
  5. Write the user a email following the template, and also mention the location of the converted repository.

Splitting converted repository into multiple repositories

  1. For every new ‘small’ repository create one copy from the ‘big’ repository.

  2. In every ‘small’ repository remove all unwanted files:

    git filter-branch --tree-filter 'rm -rf ${FILES|DIRECTORIES}' HEAD
    

Manual checks

  • check for multiple branches
  • check for tags