git bisect
バイナリ検索を使用してバグを引き起こしたコミットを見つけるコマンド。
用例
- 問題がない(good)時点と問題がある(bad)時点を指定
git bisect start <bad-commit> <good-commit>
- テストスクリプトを指定
git bisect run <テストスクリプトのファイル名>
- 手動でテスト:テストの結果、問題がない(good)場合
git bisect good
- 手動でテスト:テストの結果、問題がある(bad)場合
git bisect bad
- git bisect が現在チェックアウトしているコミットを確認
git bisect view
- 二分探索の過程を確認
git bisect log
- git bisect を実行する前の状態に戻す
git bisect reset
書式
git bisect start|bad|new|<term-new>|good|old|<term-old>|terms|skip|reset|visualize|view|replay|log|run|help [options]
公式によると以下の通り。
git bisect start [--term-{old,good}=<term> --term-{new,bad}=<term>] [--no-checkout] [<bad> [<good>...]] [--] [<paths>...] git bisect (bad|new|<term-new>) [<rev>] git bisect (good|old|<term-old>) [<rev>...] git bisect terms [--term-good | --term-bad] git bisect skip [(<rev>|<range>)...] git bisect reset [<commit>] git bisect (visualize|view) git bisect replay <logfile> git bisect log git bisect run <cmd>... git bisect help
options
--no-checkout | o not checkout the new working tree at each iteration of the bisection process. Instead just update a special reference named BISECT_HEAD to make it point to the commit that should be tested. This option may be useful when the test you would perform in each step does not require a checked out tree. If the repository is bare, --no-checkout is assumed. |
説明
バイナリ検索アルゴリズムを使用して、プロジェクトの履歴のどのコミットがバグを引き起こしたかを発見するコマンド。
- このコマンドはさまざまなサブコマンドと、サブコマンドに応じて異なるオプションを指定する。
- 最初にバグを含む「悪い」コミットと、バグが混入する前の「良い」コミットをコマンドに指定する。
- コマンドは、次にこれら2つの間のコミットを選択し、選択したコミットが「良い」か「悪い」かを確認してくる。バグが混入したコミットが見つかるまで範囲を狭め続ける。
- バグ以外にも、git bisectは、プロジェクトのある特性を変更したコミットを見つけるために使用できる(ベンチマークのパフォーマンスを向上させたコミットなど)。
- このより一般的な用法をサポートするために、 "良い"と "悪い"の代わりに "古い"と "新しい"という用語を使用することも、独自の用語を選択することも可能。
関連
- git-blameコマンド
参考リンク
- Git - git-bisect Documentation
- bisect - [Reference/Git] ぺんたん info
- git bisect で問題箇所を特定する - Qiita
- 問題のあるコミットを特定する ( git bisect ) - Qiita
- Git - Git によるデバッグ
- gitを使ってどのコミットでバグが入り込んだか特定する。git bisectの使い方 - new Nakashima()の日記
- git bisect でバグ/仕様変更のコミットを探す - ひつまぶし食べたい
- git bisectで最初のbadコミットの情報を取得する - murankの日記
- Some good revs are not ancestor of the bad rev. - daimatz.net -
その他メモ
なし。