YAMAGUCHI::weblog

海水パンツとゴーグルで、巨万の富を築きました。カリブの怪物、フリーアルバイター瞳です。

MacPortsでgit-svnを設定して使ってみた

はじめに

最近はgithubやbitbucket、さらにGoogle codeやSourceForgeなど、多くのプロジェクトホスティングサービスで分散バージョン管理を導入してますが、未だにSubversionがメインになっているところは多いと思います。
しかしながら、trunkから持ってきたものをいちいちコミットしていたのでは大変なのでやはりgitなどの分散バージョン管理はしたいなと思うわけです。
そこでgit-svnを使って今まさに行っているプロジェクトをうまいこと管理してやろうと思ったわけです。

git-svnのインストール

MacPortsでgit-svnを入れる場合はgit-coreに+svnオプションを付けます。

$ sudo port install git-core +svn

git svn cloneの実行

git cloneを行うのと同様にSubversionのレポジトリに対してgit svn cloneをします。

$ git svn clone https://svn.sourceforge.jp/svnroot/hoge

あるいはSubversionのレポジトリ直下がtrunk, branches, tagsという構成になってるなら下記のほうがよいかも。

$ git svn clone -s https://svn.sourceforge.jp/svnroot/hoge

このように-s (--stdlayout) とオプションをつけることでtrunkがmasterブランチになって、trunkとbranches直下、tags直下がそれぞれremoteブランチになります。構成が若干違う場合でもオプションを指定することで同様に設定出来ます。(-T, -b, -tオプションでディレクトリパスを指定)

gitの設定

これはgitでのお約束。

$ git config --global user.name "ymotongpoo"
$ git config --global user.email "ymotongpoo AT gmail DOT com"

変更をコミット

ここは普通にgit使う場合と同様。変更したファイルをaddして、commitします。このcommitはSubversionの中央レポジトリには反映されません。念のため。

$ git add modified.txt
$ git commit -m 'modified files'

中央レポジトリに反映

中央のレポジトリに変更を反映するにはdcommitを使います。ここでsvn commitと同様のことができます。

$ git svn dcommit

中央レポジトリの変更をローカルに反映

svn updateと同様のことをするには下記。

$ git svn rebase

以上駆け足でメモ書きでした。

dcommitできないとき(追記)

なんかdcommitしようとしたら

$ git svn dcommit
Cannot dcommit with a dirty index.  Commit your changes first, or stash them with `git stash'.

と怒られた。仕方ないのでgit stashしてみる。

$ git stash
No local changes to save

$ git svn dcommit
...
r209 = 1b6c22eaf929f45f592add41f0eac6dd95b02990 (refs/remotes/git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn
...
r210 = cc9f9a7eea03defea7b021952cef9853bdede691 (refs/remotes/git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn
...
r211 = 031673393387d56e561f69e8a90a83b9f5742774 (refs/remotes/git-svn)
No changes between current HEAD and refs/remotes/git-svn
Resetting to the latest refs/remotes/git-svn

$ git stash apply
Nothing to apply

なにこれ。結局なにも退避してないじゃないですか。でもまあdcommitできたからいいか。