ゴールデンウィークが終わっても Subversion を使い続ける方法

今週のお題ゴールデンウィーク

  • 仕事で Subversion を使っていたけど、ゴールデンウィークが明けたら Git に移行しなければならない試練があったとします
  • そんなとき、最低限の Git の操作で乗り切る方法を考えました
[ayaya@pico.ido.nu tmp]$ svnadmin create /tmp/svnrepos
[ayaya@pico.ido.nu tmp]$ svn mkdir file:///tmp/svnrepos/{trunk,branches,tags} -m 'initial commit'

リビジョン 1 をコミットしました。
  • 作業すべき Git のリモートリポジトリを clone します
[ayaya@pico.ido.nu tmp]$ git clone https://github.com/asannou/git-tasukete.git
Cloning into git-tasukete...
remote: Counting objects: 47, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 47 (delta 16), reused 40 (delta 9)
Unpacking objects: 100% (47/47), done.
[ayaya@pico.ido.nu tmp]$ cd git-tasukete/
[ayaya@pico.ido.nu git-tasukete]$ git svn init -s file:///tmp/svnrepos
[ayaya@pico.ido.nu git-tasukete]$ git svn fetch
r1 = 79c33eeda9b5be6167208fad7642be14d5a4a0f1 (refs/remotes/trunk)
  • Git の履歴を Subversion の trunk に突っ込みます
[ayaya@pico.ido.nu git-tasukete]$ git checkout trunk
Note: checking out 'trunk'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 79c33ee... initial commit

[ayaya@pico.ido.nu git-tasukete]$ git pull origin master
From https://github.com/asannou/git-tasukete
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.mkd                                         |   11 +++
 ...46\266\210\343\201\227\343\201\237\343\201\204" |    3 +
 ...43\202\204\343\202\201\343\201\237\343\201\204" |    3 +
 ...44\275\234\343\202\212\343\201\237\343\201\204" |    3 +
 ...43\201\202\343\202\214\343\201\227\343\201\246" |   92 ++++++++++++++++++++
 ...51\226\223\351\201\225\343\201\210\343\201\237" |   16 ++++
 ...47\233\264\343\201\227\343\201\237\343\201\204" |    3 +
 "git-\345\212\251\343\201\221\343\201\246"         |    9 ++
 ...46\205\213\343\201\253\346\210\273\343\201\231" |    3 +
 ...46\266\210\343\201\227\343\201\237\343\201\204" |    3 +
 10 files changed, 146 insertions(+), 0 deletions(-)
 create mode 100644 README.mkd
 create mode 100755 "git-merge\343\202\222\345\217\226\343\202\212\346\266\210\343\201\227\343\201\237\343\201\204"
 create mode 100755 "git-rebase\343\202\222\343\202\204\343\202\201\343\201\237\343\201\204"
 create mode 100755 "git-zip\343\202\222\344\275\234\343\202\212\343\201\237\343\201\204"
 create mode 100755 "git-\343\201\202\343\202\214\343\201\227\343\201\246"
 create mode 100755 "git-\343\202\263\343\203\237\343\203\203\343\203\210\343\201\231\343\202\213\343\201\256branch\343\202\222\351\226\223\351\201\225\343\201\210\343\201\237"
 create mode 100755 "git-\345\211\215\345\233\236\343\201\256\343\202\263\343\203\237\343\203\203\343\203\210\350\252\254\346\230\216\346\226\207\343\202\222\346\233\270\343\201\215\347\233\264\343\201\227\343\201\237\343\201\204"
 create mode 100755 "git-\345\212\251\343\201\221\343\201\246"
 create mode 100755 "git-\346\234\200\345\276\214\343\201\256\343\202\263\343\203\237\343\203\203\343\203\210\343\201\256\347\212\266\346\205\213\343\201\253\346\210\273\343\201\231"
 create mode 100755 "git-\347\211\271\345\256\232\343\201\256\343\202\263\343\203\237\343\203\203\343\203\210\343\202\222\345\217\226\343\202\212\346\266\210\343\201\227\343\201\237\343\201\204"
[ayaya@pico.ido.nu git-tasukete]$ git svn dcommit
Committing to file:///tmp/svnrepos/trunk ...
        A       README.mkd
        A       git-mergeを取り消したい
        A       git-rebaseをやめたい
        A       git-zipを作りたい
        A       git-あれして
        A       git-コミットするのbranchを間違えた
        A       git-前回のコミット説明文を書き直したい
        A       git-助けて
        A       git-最後のコミットの状態に戻す
        A       git-特定のコミットを取り消したい
Committed r2
        A       git-zipを作りたい
        A       git-rebaseをやめたい
        A       git-特定のコミットを取り消したい
        A       README.mkd
        A       git-助けて
        A       git-コミットするのbranchを間違えた
        A       git-前回のコミット説明文を書き直したい
        A       git-mergeを取り消したい
        A       git-最後のコミットの状態に戻す
        A       git-あれして
r2 = e44b9b50286ca01befd5301db65303689e811536 (refs/remotes/trunk)
No changes between current HEAD and refs/remotes/trunk
Resetting to the latest refs/remotes/trunk
[ayaya@pico.ido.nu git-tasukete]$ svn log file:///tmp/svnrepos/trunk
------------------------------------------------------------------------
r2 | ayaya | 2012-05-08 23:26:44 +0900 (火, 08  5月 2012) | 1 line

Merge https://github.com/asannou/git-tasukete into HEAD
------------------------------------------------------------------------
r1 | ayaya | 2012-05-08 23:23:25 +0900 (火, 08  5月 2012) | 1 line

initial commit
------------------------------------------------------------------------
[ayaya@pico.ido.nu git-tasukete]$ svn ls file:///tmp/svnrepos/trunk
README.mkd
git-mergeを取り消したい
git-rebaseをやめたい
git-zipを作りたい
git-あれして
git-コミットするのbranchを間違えた
git-前回のコミット説明文を書き直したい
git-助けて
git-最後のコミットの状態に戻す
git-特定のコミットを取り消したい
  • これで準備が整いました
  • Subversion の trunk には一切コミットはしません
  • 作業をするときは、まず trunk から branch を作成します
[ayaya@pico.ido.nu git-tasukete]$ git svn branch git-yametai
Copying file:///tmp/svnrepos/trunk at r2 to file:///tmp/svnrepos/branches/git-yametai...
Found possible branch point: file:///tmp/svnrepos/trunk => file:///tmp/svnrepos/branches/git-yametai, 2
Found branch parent: (refs/remotes/git-yametai) e44b9b50286ca01befd5301db65303689e811536
Following parent with do_switch
Successfully followed parent
r3 = bc1c84748828cb61d782fe53674ddbcfff4fc229 (refs/remotes/git-yametai)
  • あとは普通に branch をチェックアウトして仕事をしましょう
[ayaya@pico.ido.nu svnwork]$ svn co file:///tmp/svnrepos/branches/git-yametai
A    git-yametai/git-zipを作りたい
A    git-yametai/git-rebaseをやめたい
A    git-yametai/git-特定のコミットを取り消したい
A    git-yametai/README.mkd
A    git-yametai/git-助けて
A    git-yametai/git-コミットするのbranchを間違えた
A    git-yametai/git-前回のコミット説明文を書き直したい
A    git-yametai/git-mergeを取り消したい
A    git-yametai/git-最後のコミットの状態に戻す
A    git-yametai/git-あれして
リビジョン 3 をチェックアウトしました。
[ayaya@pico.ido.nu svnwork]$ cd git-yametai/
[ayaya@pico.ido.nu git-yametai]$ svn log
------------------------------------------------------------------------
r3 | ayaya | 2012-05-08 23:27:56 +0900 (火, 08  5月 2012) | 1 line

Create branch git-yametai
------------------------------------------------------------------------
r2 | ayaya | 2012-05-08 23:26:44 +0900 (火, 08  5月 2012) | 1 line

Merge https://github.com/asannou/git-tasukete into HEAD
------------------------------------------------------------------------
r1 | ayaya | 2012-05-08 23:23:25 +0900 (火, 08  5月 2012) | 1 line

initial commit
------------------------------------------------------------------------
  • 仕事が終わって branch にコミットをしたら、それを Git に merge します
[ayaya@pico.ido.nu git-tasukete]$ git fetch
[ayaya@pico.ido.nu git-tasukete]$ git svn fetch
        A       git-やめたい
r4 = 70d2151942542fc1a844f4e81c71dbe1c7975fd0 (refs/remotes/git-yametai)
[ayaya@pico.ido.nu git-tasukete]$ git checkout origin/master
Previous HEAD position was bc1c847... Create branch git-yametai
HEAD is now at 40c9625... Merge pull request #4 from kentaroi/fix_branch_wo_machigaeta
[ayaya@pico.ido.nu git-tasukete]$ git merge --squash git-yametai
Updating 40c9625..70d2151
Fast-forward
Squash commit -- not updating HEAD
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 "git-\343\202\204\343\202\201\343\201\237\343\201\204"
  • Subversion を使っていることがばれないように、いい感じのメッセージをつけて commit して push しましょう
[ayaya@pico.ido.nu git-tasukete]$ git commit
[ayaya@pico.ido.nu git-tasukete]$ git show
commit 0eb69945611270075a4b0dce99ef62a34f6a174b
Author: ayaya <ayaya@pico.ido.nu>
Date:   Wed May 9 00:47:16 2012 +0900

    やめたい を作った

diff --git "a/git-\343\202\204\343\202\201\343\201\237\343\201\204" "b/git-\343\202\204\343\202\201\343\201\237\343\201\204"
new file mode 100644
index 0000000..e69de29
[ayaya@pico.ido.nu git-tasukete]$ git push origin HEAD:master
  • git merge --squash git-yametai の時点で、コンフリクトが発生するかもしれません
  • その場合 trunk を更新したり
[ayaya@pico.ido.nu git-tasukete]$ git checkout trunk
[ayaya@pico.ido.nu git-tasukete]$ git pull origin master
[ayaya@pico.ido.nu git-tasukete]$ git svn dcommit
  • branch を新たに作成したりして Subversion 側でコンフリクトを解決してください
[ayaya@pico.ido.nu git-tasukete]$ git svn branch git-yametai2


はい


以上
いかがでしたでしょうか
今週の
「そんなことやってるうちに Git の使い方おぼえてきた」。


というわけで
ぜひみなさんも
Subversion を使い続けていただけたらと思いまして、
お忙しいところすみませんが
どうぞよろしくおねがいいたします。
ではまた失礼いたします。