Migration from SVN to Git

Prepare authors mapping file

The migration includs the commit history from svn, so we need an account mapping file between svn and github accounts. Here’s the sample content of mapping file:

ts32145 = James Lu <james.lu@example.com>
cm56426 = Catalin Mike <catalin.mike@example.com>

The svn account should be set on the left and the github account should be set on the right with the email.

Please notice that all the authors of this svn project should be included in this mapping file, or the migration will not proceed successfully.

If some of the authors don’t have any github account created, you should also provide this formatted file. The only difference is if the github account exists, the account name in the commit history dashboard of github is linkable to its own profile page, or it’s plain text.

Here are 2 approaches to get the authors list from svn:

Eclipse SVN Plugin

Open svn repository history -> Right click anywhere in the history tab, then click Quick Filter -> Check Author then you can see the authors list

svn command

The following svn command of svn could also be executed to get the authors list if you get the svn client installed.

svn log -q file:///path/to/subversion/project | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq

Migrate Trunk & Branch

  • Create git repository

mkdir ses && cd ses
mkdir trunk && cd trunk
  • Init git repository

git init
git svn init https://path/to/svn/project
  • Paste the authors.txt to the repository root path and config account
    mapping file:

git config svn.authorsfile authors.txt
  • Fetch code

git svn fetch
  • Add remote and push code to git

git remote add origin ssh://path/to/git/repository.git
git push origin master

Migrate Tags

Git uses two main types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn’t change – it’s just a pointer to a specific commit.

Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason don’t want to keep the other information, lightweight tags are available too.

Annnotated tag
  • Create tag v1.0

git tag –a v1.0 –m “first tag”
  • Review tags

git tag
  • Push tag to remote

push origin v1.0
Lightweight tag
  • Create tag v1.0-lw

git tag v1.0-lw
  • Review tags

git tag
  • Push tag to remote

git push origin v1.0-lw
    原文作者:nasuf
    原文地址: https://segmentfault.com/a/1190000010161546
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞