今回はgit svnでブランチの扱いやマージのやり方等を学んでみましょう。
使用するコマンドは基本的に普通のgitと同じです。
(細かいオプションの説明はしませんので、後でググって調べてね
●前提
Subversionリポジトリ上のブランチはsvnコマンドで作成する。
基本的にブランチはtrunkから作成される。
●まず、リモートのブランチを確認してみましょう。
既にリモートのリポジトリにはbranches/の中に複数のブランチがあるという想定です。
shell > git branch -a (リモートとローカルのブランチを両方表示します
* master
remotes/origin/trunk
あらら? リモートにあるはずのブランチが表示されてませんね?
fetchをしてリモートの情報を取り込んでみましょう。
shell > git svn fetch
Found possible branch point: http://sabakan.org/svn/git_svn_test1/trunk => http://sabakan.org/svn/git_svn_test1/branches/20150816_kimodameshi, 5
Found branch parent: (refs/remotes/origin/20150816_kimodameshi) 741f4b928413ecb7b5f7984c58014c9126582cf5
Following parent with do_switch
Successfully followed parent
r6 = ef0cd7c2262cc34e496b08d7cf74f26cb0fc9cf9 (refs/remotes/origin/20150816_kimodameshi)
Found possible branch point: http://sabakan.org/svn/git_svn_test1/trunk => http://sabakan.org/svn/git_svn_test1/branches/20150916_halloween, 5
Found branch parent: (refs/remotes/origin/20150916_halloween) 741f4b928413ecb7b5f7984c58014c9126582cf5
Following parent with do_switch
Successfully followed parent
r7 = 623caa0acaf38638d3cff82303379c8301bf1fb9 (refs/remotes/origin/20150916_halloween)
ブランチの情報がfetchされましたね。
もう一回、git branch -aをしてみましょう。
shell > git branch -a
* master
remotes/origin/20150816_kimodameshi
remotes/origin/20150916_halloween
remotes/origin/trunk
ちゃんとリモートブランチの内容が表示されましたね。
●ローカルに作業ブランチの作成
ローカルに作業ブランチを作成してみましょう。
リモートの20150816_kimodameshiから作業ブランチを作成しましょう。
shell > git checkout -b 20150816_kimodameshi remotes/origin/20150816_kimodameshi
Switched to a new branch '20150816_kimodameshi'
これでローカル作業ブランチの作成とブランチの切り替えができました。
git svn infoでブランチの情報を確認してみましょう。
shell > git svn info
Path: .
URL: http://sabakan.org/svn/git_svn_test1/branches/20150816_kimodameshi
Repository Root: http://sabakan.org/svn/git_svn_test1
Repository UUID: 7560baa6-3e80-11e5-b682-712d2b13a4d3
Revision: 6
Node Kind: directory
Schedule: normal
Last Changed Author: taka
Last Changed Rev: 5
Last Changed Date: 2015-08-15 10:34:39 +0900 (土, 15 8月 2015)
試しに適当なファイルを修正してリモートにcommitしてみましょう。
shell > vim public/index.php
shell > git add .
shell > git commit -m "test commit"
shell > git svn dcommit
ちゃんとリモートの20150816_kimodameshi ブランチにcommitされましたか?
●マージをする
それでは次はマージをしてみましょう。
20150816_kimodameshiで加えた変更をtrunkにマージしてみましょう。
まず、ローカルのリポジトリをmasterに切り換えます。
shell > git checkout master
shell > git merge --no-ff 20150816_kimodameshi
コミットのメッセージを入力する画面になると思います(デフォルトだとviが立ちががると思います)ので、
何か適当にメッセージを書き込んで保存してください。
Merge made by the 'recursive' strategy.
public/index.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
これでマージが終わりました。
最後にリモートにコミットしましょう。
shell > git svn dcommit
Committing to http://sabakan.org/svn/git_svn_test1/trunk ...
M public/index.php
Committed r11
M public/index.php
r11 = a7eb63ebbfb592cc98753051ff79221380984384 (refs/remotes/origin/trunk)
No changes between afb39cbe287d570b6844d6f1132f8a0462430056 and refs/remotes/origin/trunk
Resetting to the latest refs/remotes/origin/trunk
ちゃんと、リモートのtrunkにマージされましたね?
既に運用フェーズに入った案件では、こんな感じでブランチを細かく分けて、
さらに各ブランチ用のテストサーバーを用意しておけば、QAの人達も各ブランチのテストがしやすくなりますよね。
今日はここまでハァハァ。。。
コメント