いつ頃からかはわからないが、Git for Windowsをインストールすると、git-flowコマンドもバンドルされるようになっていた。
git-flow windows インストール
で検索すると、いまだに git clone http://github.com/nvie/gitflow.git
とか出てくるのでメモ。
環境
Windows 10 Pro 64bit、Git for Windows v2.24.0で確認。
Chocolatey でインストールおよびアップデートしているので、インストーラーを使った場合は未確認だが、おそらく変わらない。
状況
Git for Windowsをインストールすると、git-flowコマンドも使えるようになっていた。含まれるようになったのは、v2.6.4 からの模様。
Installing on Windows · petervanderdoes/gitflow-avh Wiki · GitHub
Git for Windows v2.24.0の場合、git-flowはAVH Editionのv1.12.3。
$ git --version git version 2.24.0.windows.1 $ git flow usage: git flow <subcommand> Available subcommands are: init Initialize a new git repo with support for the branching model. feature Manage your feature branches. bugfix Manage your bugfix branches. release Manage your release branches. hotfix Manage your hotfix branches. support Manage your support branches. version Shows version information. config Manage your git-flow configuration. log Show log deviating from base branch. Try 'git flow <subcommand> help' for details. $ git flow version 1.12.3 (AVH Edition)
AVH Editionについて
master, develop, feature, hotfix, release ブランチを使う、いわゆるgit-flowは以下。developブランチの最終コミットが2012年。
bugfix や support を加えて拡張したのがAVH Edition。こちらも2012年ごろにはあったはず。
git-flowの基本となるfeature, hotfix, releaseは git-flow cheatsheet などいくらでも説明があるので、bugfixとsupportについて説明。
bugfixブランチ
その名の通り、バグフィックスを行うブランチっぽい。
Reference: git flow bugfix · petervanderdoes/gitflow-avh Wiki · GitHub
hotfixと似ているが、違いとしてはhotfixはmasterからブランチを作成し、終了するとmasterとdevelopにマージするのに対し、bugfixはdevelopからブランチを作成し、終了するとdevelopにマージする。
$ git flow bugfix start bugfix-1 Switched to a new branch 'bugfix/bugfix-1' Summary of actions: - A new branch 'bugfix/bugfix-1' was created, based on 'develop' - You are now on branch 'bugfix/bugfix-1' Now, start committing on your bugfix. When done, use: git flow bugfix finish bugfix-1 $ echo 'bugfix' > bugfix.txt && git add -A && git commit -m 'bugfix' $ git flow bugfix finish --no-ff bugfix-1 Summary of actions: - The bugfix branch 'bugfix/bugfix-1' was merged into 'develop' - bugfix branch 'bugfix/bugfix-1' has been locally deleted - You are now on branch 'develop'
また、それ以外にもhotfixとの違いとして、デフォルトではhotfixは1つしか開始できないが、bugfixは複数開始できる。
$ git flow hotfix start hotfix-1 Switched to a new branch 'hotfix/hotfix-1' # hotfixの終了前に、別のhotfixを開始しようとするとエラーになる $ git flow hotfix start hotfix-2 Fatal: There is an existing hotfix branch 'hotfix-1'. Finish that one first. # multi-hotfixをtrueにすれば複数のhotfixを作成可能 $ git config --add gitflow.multi-hotfix true $ git flow hotfix start hotfix-2 Switched to a new branch 'hotfix/hotfix-2' # bugfixはデフォルトで複数同時に開始可能 $ git flow bugfix start bugfix-2 Switched to a new branch 'bugfix/bugfix-2' $ git flow bugfix start bugfix-3 Switched to a new branch 'bugfix/bugfix-3'
hotfixが最優先で対応しなければならない問題なのに対し、bugfixは緊急度が低く、次回リリースに含めればいいような、致命的ではない問題への対応に使用するものと思われる。
というか、start/finish程度の使い方だと、実質featureのエイリアス。
supportブランチ
任意の別ブランチから派生させるブランチ。共同作業のサポートかと思ったが、どうも挙動が想像と違う、後述。
Reference: git flow support · petervanderdoes/gitflow-avh Wiki · GitHub
ドキュメントの更新日は2019/11/9現在、 4 Aug 2017
になっているが、実際の挙動と差異がある。
ドキュメントでは、startの説明に以下のように記述されている。
Description Start a new support branch name <version>, optionally basing it on <base> instead of <master> Synopsis git flow support start [-h] [-F] <version> [<base>]
だが、v1.12.3では、baseブランチの指定が必須になっている。
$ git flow support start support-1 Missing argument <base> usage: git flow support start [-h] [-F] <version> <base> Start a new support branch name <version> based on <base>
v1.12.3時点で、startとrebaseしかコマンドがないため、これ単体でfinishに該当する終了処理が行なえない。
startで任意のブランチからサポートブランチを作成し、Gitサーバーにpush、そこから元ブランチにプルリクエストを投げたりするのかな?
# hotfixに対するサポートブランチを作成 $ git flow support start support-1 hotfix/hotfix-1 Switched to a new branch 'support/support-1' Summary of actions: - A new branch 'support/support-1' was created, based on 'hotfix/hotfix-1' - You are now on branch 'support/support-1' $ echo 'support' > support.txt && git add -A && git commit -m 'support' # rebaseすると、startで指定したbaseではなく、developからrebaseする $ git flow support rebase support-1 Will try to rebase '' which is based on 'develop'... First, rewinding head to replay your work on top of it... Applying: support
各ブランチの設定変更
git flow init
すると、 .git/config
に設定が追加される。デフォルトだと以下。
[gitflow "branch"] master = master develop = develop [gitflow "prefix"] feature = feature/ bugfix = bugfix/ release = release/ hotfix = hotfix/ support = support/ versiontag = [gitflow "path"] hooks = ${git_project_root}/.git/hooks
masterやdevelopとして扱うブランチ名や、各コマンドで操作するブランチ名の接頭語などを変更可能。
振り返り
素のgit-flowだと、軽微な修正をhotfixにするのかfeatureにするのかで迷うことがあった。
AVH Editionだとbugfixが追加されたおかげで、緊急度が高ければhotfix、そうでなければbugfixと切り分けることができ、だいぶ使いやすい。
実際の運用では、Jiraで管理している課題の種類に合わせてfeatureやbugfixをstartし、finishはせずGitサーバーにプルリクエストしてマージしているので、supportも具体的なコードの修正例として使えるかと思う。