準備
SVN から Git ベースのバージョン管理に移行する最初のステップとして、移行推進担当者のローカルマシーンを整備します。このステップでは、便利なユーティリティスクリプトをダウンロードし、(必要に応じて) ケースセンシティブなファイルシステムをマウントし、SVN のオーサー情報を Git にマップします。
これ以降の作業はすべて移行推進担当者のローカルマシーン上で実行します。
移行処理スクリプトのダウンロード
Git comes with most of the necessary tools for importing an SVN repository; however, there are a few missing bits of functionality that Atlassian has rolled into a handy JAR file. This file will be integral to the migration, so be sure to download svn-migration-scripts.jar
from Atlassian’s Bitbucket account. This guide assumes that you’ve saved it in your home directory. Disclaimer: for the svn migration you need a case-sensitive filesystem and this does not work on NTFS. We suggest using this on a Linux machine.
Once you’ve downloaded it, it’s a good idea to verify the scripts to make sure you have the Java Runtime Environment, Git, Subversion, and the git-svn utility installed. Open a command prompt and run the following:
java -jar ~/svn-migration-scripts.jar verify
このコマンドを実行すると、移行処理に必要なプログラムがインストールされていない場合はコンソールにエラーメッセージを表示します。インストールされていないプログラムがある場合は、次に進む前に必ずインストールしてください。
If you get a warning about being unable to determine a version, run export LANG=C
(*nix) or SET LANG=C
(Windows) and try again.
OS X が稼動しているマシーン上で移行処理を行う場合は、次のような警告も表示されます:
You appear to be running on a case-insensitive file-system. This is unsupported, and can result in data loss.
これについては次のセクションで説明します。
ケースセンシティブなディスクイメージのマウント
Git への移行処理は、リポジトリの破損を防止するためにはケースセンシティブなファイルシステム上で行う必要があります。OS X のファイルシステムはケースセンシティブではないため、移行処理を OS X 上で行う場合は問題が生じます。
If you’re not running OS X, all you need to do is create a directory on your local machine called ~/GitMigration
. This is where you will perform the conversion. After that, you can skip to the next section.
If you are running OS X, you need to mount a case-sensitive disk image with the create-disk-image
script included in svn-migration-scripts.jar
. It takes two parameters:
- 作成するディスクイメージのサイズ (単位はギガバイト)。このサイズは、移行対象の SVN リポジトリよりも大きいサイズである限り任意の値を指定することができます。
- The name of the disk image. This guide uses
GitMigration
for this value.
For example, the following command creates a 5GB disk image called GitMigration
:
java -jar ~/svn-migration-scripts.jar create-disk-image 5 GitMigration
The disk image is mounted in your home directory, so you should now see a directory called ~/GitMigration
on your local machine. This serves as a virtual case-sensitive filesystem, and it’s where you’ll store the converted Git repository.
オーサー情報の抽出
SVN では、各々のコミットにおいて記録されるオーサー情報はユーザー名のみです。一方 Git では、オーサーのフルネームと E メールアドレスを記録します。従って、SVN ユーザー名を Git においてそれに対応する情報にマップするテキストファイルを作成する必要があります。
次のコマンドを実行するとこのテキストファイルを自動的に生成することができます:
cd ~/GitMigration
java -jar ~/svn-migration-scripts.jar authors <svn-repo> > authors.txt
Be sure to replace <svn-repo>
with the URI of the SVN repository that you want to migrate. For example, if your repository resided at https://svn.example.com
, you would run the following:
java -jar ~/svn-migration-scripts.jar authors https://svn.example.com > authors.txt
このコマンドを実行すると、SVNリポジトリ内のすべてのオーサーのユーザー名、ならびに生成された名前と電子メールアドレスが含まれる authors.txt
というテキストファイルが作成されます。このファイルは次のような内容です:
j.doe = j.doe<j.doe@mycompany.com>
m.smith = m.smith<m.smith@mycompany.com>
等号の右側部分を、対応するユーザーのフルネームと電子メールアドレスに書き換えます。例えば、次のように書き換えます:
j.doe = John Doe <john.doe@atlassian.com>
m.smith = Mary Smith <mary.smith@atlassian.com>
まとめ
これでマイグレーションスクリプト、ディスクイメージ (OS X のみ)、オーサー情報が揃い、SVN履歴を新たな Git リポジトリにインポートする準備ができました。次のステップでは、この変換機能について説明します。