Skip to content

Instantly share code, notes, and snippets.

@amura2406
Created August 23, 2016 07:58
Show Gist options
  • Save amura2406/a610a6a50690ceda96b6858f2435227f to your computer and use it in GitHub Desktop.
Save amura2406/a610a6a50690ceda96b6858f2435227f to your computer and use it in GitHub Desktop.
Tutorial to migrate from SVN to Git

Install svn2git.

On all systems you can install as a Ruby gem if you already have Ruby and Git installed.

sudo gem install svn2git

Checkout SVN Repo

Checkout the latest SVN Repository of the project you want to convert.

svn co --username <your_name> https://svn.server.com/repository/trunk

Map Authors (Optional)

Prepare an authors file so svn2git can map SVN authors to Git authors. If you choose not to create the authors file then commits will not be attributed to the correct Git user. Some users may not consider this a big issue while others will want to ensure they complete this step. If you choose to map authors you will be required to map every author that is present on changes in the SVN repository. If you don't, the conversion will fail and you will have to update the author file accordingly. The following command will search through the repository and output a list of authors.

svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq

Use the output from the last command to construct the authors file. Create a file called authors.txt and add one mapping per line.

janedoe = Jane Doe <janedoe@example.com>
johndoe = John Doe <johndoe@example.com>

Convert to Git format

There are several way to convert the current project to Git format.

  1. The svn repo is in the standard layout of (trunk, branches, tags) at the root level of the repo.
svn2git http://svn.example.com/path/to/repo --authors /path/to/authors.txt
  1. The svn repo is NOT in standard layout and has only a trunk at the root level of the repo.
svn2git http://svn.example.com/path/to/repo --trunk trunk --nobranches --notags --authors /path/to/authors.txt
  1. The svn repo is NOT in standard layout and has no trunk, branches, or tags at the root level of the repo. Instead the root level of the repo is equivalent to the trunk and there are no tags or branches.
svn2git http://svn.example.com/path/to/repo --rootistrunk --authors /path/to/authors.txt

There are still several ways and can be refer to this link.

Create Git Project

Create a new Git project, where you will eventually push your converted code. Copy the SSH or HTTP(S) repository URL from the project page. Add the GitLab repository as a Git remote and push all the changes. This will push all commits, branches and tags.

Add global config if you want

git config --global user.name "John Doe"
git config --global user.email "john.doe@gmail.com"

Push the repo to remote server

cd existing_folder
git init
git remote add origin git@gitserver:<group>/<project>.git
git add .
git commit
git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment