Skip to content

Instantly share code, notes, and snippets.

@tomohiro
Last active July 29, 2020 12:13
Show Gist options
  • Save tomohiro/5820939 to your computer and use it in GitHub Desktop.
Save tomohiro/5820939 to your computer and use it in GitHub Desktop.
Subversion のリポジトリを Git リポジトリへ変換し GitHub に登録するまでの手順

Subversion のリポジトリを Git リポジトリへ変換し GitHub に登録するまで

Subversion ユーザ情報と Git ユーザ情報をマッチングするためのテキストファイルを作成

フォーマット:

{svn username} = {git username} <git user mail>

実際はこんな感じ:

$ cat user.txt
ichiro = Ichiro Suzuki <ichiro@example.com>
john = John Doe <john@example.com>
...
...
(no author) = No Name <noname@example.com>  # CVS から Subversion へ移行したリポジトリの場合この行が必要になる

Subversion リポジトリを Git リポジトリとしてチェックアウトする

リポジトリを作成:

$ mkdir myrepo
$ cd myrepo
$ git init

Git の設定 .git/config に Subversion リポジトリの情報を追加:

$ vi .git/config
[svn-remote "svn"]
    noMetadata = 1
    url = http://subversion.example.com/svn/myrepo
    fetch = trunk:refs/heads/master
    branches = branches/*:refs/heads/*
    tags = tags/*:refs/tags/*
[svn]
    authorsfile = /path/to/users.txt  # 先ほど作成したユーザマッチング用のテキストファイルを指定

リポジトリを fetch する:

$ git svn fetch

fetch した後,なぜか全てのファイルに削除属性がついてる場合があるので,reset する:

$ git status       # D 属性がついてる場合がある
$ git reset --hard # svn head の状態に戻す

GitHub に登録する

GitHub 上でリポジトリを作成した後,origin に GitHub のリポジトリの URL を登録する:

$ cd myrepo
$ git remote add origin git@github.com:myname/myrepo.git

GitHub の設定を config に追加し,Subversion セクションの情報を削除する:

$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:myname/myrepo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

設定が終わったら GitHub へ push する:

$ git push -u origin master # master を push (Subversion では trunk だったもの)
$ git push --all            # 全ての branch を push
$ git push --tags           # 全ての tag を push

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment