Import SVN folder as Git branch

Steps overview

  1. Import each SVN folder as individual temporary Git repos
  2. Create a new Git main repo
  3. In main Git repo, set up branches to track each master branches in temporary Git repos

Import each SVN folder as individual temporary Git repos

First, you may need to map SVN users into Git users.

$ cd ~/projects/
$ svn co svn://svnserver.com/projectX
$ cd projectX/
$ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > ../projects/authors.txt

Then edit the file as you need, for example mine:
pellaeon = Pellaeon Lin <nfsmwlin@gmail.com>

Import your SVN folders

$ cd ~/projects/
$ git svn clone -A ~/projects/authors --no-metadata svn://svnserver.com/projectX/your/svn/folder1 temp1
$ git svn clone -A ~/projects/authors --no-metadata svn://svnserver.com/projectX/your/svn/folder2 temp2
(and so on)

Create a new Git main repo


$ mkdir -p ~/projects/mainrepo/
$ cd ~/projects/mainrepo/
$ git init .

In main Git repo, set up branches to track each master branches in temporary Git repos

Pull in master

$ git remote add temp1 ~/projects/temp1
$ git pull temp1 master

For each branches, pull in from corresponding temp repos

$ git checkout -b temp2
$ git remote add temp2 ~/projects/temp2
$ git pull temp2 master

Now you have the main repo you wanted, you can delete the temp repo.

References

2 thoughts on “Import SVN folder as Git branch

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s