Subversionのリポジトリからgitリポジトリに移行する
会社で管理していたリポジトリをsvnからgitに移行したときの方法。
1.コミッターのリストを作成する
移行対象のsvnリポジトリをローカルにチェックアウト(svn checkout
)している状態で、そのルートディレクトリ下で
$ svn log ^/ --xml | perl -ne 'print if /^<author/' | sort -u | perl -pe 's/<author>(.*?)<\/author>/$1 = /' > users.txt
を実行。 こうするとusers.txtには
foo =
bar =
のようなリストが作成される。それを編集して
foo = foo <foo@example.com>
bar = bar <bar@example.com>
のように、氏名 + <メールアドレス> を追記する。
2. git svnでcloneを作成する
次にgit svn
コマンドで該当svnリポジトリをcloneする。
$ git svn clone http://www.example.com/path/to/hoge --no-metadata --authors-file=users.txt --trunk=trunk hoge
--no-metadata
オプションは、コミットログにsvnのメタ情報を残さないための設定。
--authors-file
オプションには、1で編集したファイルを指定する。こうすると、コミットログのコミッターがusers.txt
で編集した内容に置換される。
また今回、対象のリポジトリにはtrunkしか存在しなかったため、--trunk
オプションでtrunkのみを指定した。
3. svn:ignoreの設定をgitに反映する
次に、svn:ignoreの設定を反映させるために、gitignoreファイルを作成する。
$ cd hoge/
$ git svn show-ignore > .gitignore
ファイルを作成したらコミットする。
$ git add .gitignore
$ git commit
4. 移行先のgitリポジトリにpushする
最後に、移行先のリモートリポジトリを設定してpushする。
$ git remote add origin username@example.com:/path/to/hoge.git
$ git push origin