hollyさんのwiki

git flow導入に関すること。A successful Git branching modelを理解しないといけない。

ここにざっくりまとめてくれていた。そのまま引用。こういうことだそうな。
  • 中央リポジトリとみなす origin を用意する
  • origin は master と develop のブランチを持つ
  • master はリリース用のブランチで、リリースしたらタグ付けする(SVN でいう trunk と tag)
  • develop は開発用ブランチ。リリース準備ができたら master へマージする
  • 細かい開発は develop で行うが、新機能追加などは develop から分岐させたフィーチャーブランチで行う

そしてこういう運用をする。どこかからか忘れたが引用。つまりmasterを直接使うことはない
  • master ブランチは tag 専用とする
  • 新機能開発は feature ブランチで行う
  • 細かい開発は develop ブランチで行う
  • release ブランチはタグを打つための作業を行う
  • hotfix ブランチはバグフィックスを行う専用のブランチで develop と master に反映する

インストール

msysgitが必要。ここみるとよい。しかしwindowsは使いたくないものだ

clone

適当な場所にclone
git clone git://github.com/nvie/gitflow.git

submodule clone

cd gitflow
git submodule init
git submodule update

getopt.exe

util-linux-ng for Windowsのなかにあるgetopt.exeをgitのbinにコピーする。自分の環境だとc:\Program Files (x86)\Git\binとなっている

libintl3.dll

LibIntl for Windowsもいるようだ。コピー先は同じ

install

これはコマンドプロンプトでやること
contrib\msysgit-install.cmd "C:\Program Files (x86)\Git"
めんどくさいことに管理者権限じゃないとだめとか言うときは
cd C:\path\to\gitflow
contrib\msysgit-install.cmd "C:\Program Files (x86)\Git"
というようなバッチファイルを作成して、explorerから右クリックで管理者権限で実行するとgit-flowのコマンドがC:\Program Files (x86)\Git\binにインストールされる

使い方

初歩的な使い方

リポジトリを作成し、以下を実行する。既に作成済のリポジトリも以下の手順で問題ない。
mkdir test
cd test
git flow init
Which branch should be used for bringing forth production releases?
   - master
Branch name for production releases: [master]
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []

branchを確かめるとこのようになる。

git branch -a
* develop
  master

リモートのリポジトリが設定されていない場合は準備をしておくこと。cloneした場合はしなくてよい
git remote add $url

機能を追加する

developではあんまり開発はしないほうがよさそうな。というわけでfeature branchを作成して開発をする
git flow feature start helloworld
Switched to a new branch 'feature/helloworld'

Summary of actions:
- A new branch 'feature/helloworld' was created, based on 'develop'
- You are now on branch 'feature/helloworld'

Now, start committing on your feature. When done, use:

     git flow feature finish helloworld
となりfeature/helloworldに切り替わる。どのfeature branchかあるか確認する場合は
git flow feature
で確認することができる。とりあえずこのbranchで適当に開発してみる。

開発完了

develop branchに内容をmergeする
$ git flow feature finish hello
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
 README    | 1 +
 hello.txt | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 README
 create mode 100644 hello.txt
Deleted branch feature/helloworld (was eb87489).

Summary of actions:
- The feature branch 'feature/helloworld' was merged into 'develop'
- Feature branch 'feature/helloworld' has been removed
- You are now on branch 'develop'
これで作業していたfeature branchが削除される。

リリース準備

↓で。バージョンを指定するのが慣例のようだ。
git flow release start 0.01
Switched to a new branch 'release/0.01'

Summary of actions:
- A new branch 'release/0.01' was created, based on 'develop'
- You are now on branch 'release/0.01'

Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

     git flow release finish '0.01'
ここでrelease noteを書くなり、changelogを書くなり。的なことをして、commitする
vi CHANGELOG # とかv0.01 releaseとか
git add CHANGELOG
git commit -m "edit CHANGELOG v0.01"
[release/0.01 45e8299] edit CHANGELOG v0.01
 1 file changed, 1 insertion(+)
 create mode 100644 CHANGELOG

リリースする

git flow release finish 0.01
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
 CHANGELOG | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 CHANGELOG
Deleted branch release/0.01 (was 45e8299).

Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'master'
- The release was tagged '0.01'
- Release branch has been back-merged into 'develop'
- Release branch 'release/0.01' has been deleted
エディタが開くので、tagに対するコメントを入力せよと出るので、何か入力すること。これでdevelop/margeにmergeされて、release branchで指定したバージョンがtagとして生成される。っで、develop branchに戻る

push

これは同じ
git push origin develop
git push origin 0.01

git flowの使い方を書いたところを見るとmasterはpullしていないのが多いがいると思うのだが
git pull origin master

pushするときに当然ながら先に更新されている場合があると失敗することになるので、そういう場合は以下を実行してからもう一回pushする
git pull --rebase origin develop
グラフが気になるならここに載っているような運用をするほうがいいだろう。

hotfix

不具合用。ほぼfeatureと同じだが一通り試してみる

branch作成

git flow hotfix start 0.02-fix
hotfix/0.02-fixとしてbranchが作成、切り替わるので、このブランチ上でhotfix用作業を行うこと。release branchにはいかずに終了後はdevelopにmerge, masterにtagが割り当てられるので、release branchで行うようなchangelog変更作業などもあわせて行うこと。

finish

commitまでが終わったら以下を実施
git flow hotfix finish 0.02-fix
これでdevelop, masterにまで反映される

開発途中のbranchをpushしたい場合

publishを使えばいい。とあるfeature branchをpushしたい場合は↓を実行する
git flow feature publish $branch_name
2回目以降はできない?のかよくわからないので、以下でもいい気がする
git push origin feature/$branch_name

取り込むときは
git flow feature pull origin $branch_name

複数人で開発する場合

  1. develop branchは常にみんなの開発物が集まるようにしたほうがよい
  2. feature branchは基本的にはそれぞれで適用にやればよさそう。必要なときのみpublishして公開、共有するとよいが不要になったときに公開したfeature branch消すのがめんどくさいので、あまりpublishは必要ないかも
  3. feature/hotfix branchをきることを意識づけるところから
タグ

Wiki内検索

Menu

ここは自由に編集できるエリアです。

管理人/副管理人のみ編集できます