git bisect

git

書き方

git bisect start <bad> <good>

コミットの範囲を半分ずつ絞り、問題が最初に入ったコミットを見つけます。終わったらgit bisect resetが必要で、忘れるとブランチのないコミットに留まったままになります。

よく使うオプション

オプション意味
start <bad> <good>begin, naming a broken and a working commit
goodmark the checked-out commit as working
badmark it as broken
skipthis commit cannot be tested
run <cmd>let a command decide by its exit code
resetstop and go back to where you were

git bisect start HEAD v1.1.0

starts the search between the last release and now

git bisect run npm test

finds the first failing commit with no further input

git bisect reset

ends the session; skipping this leaves you on a detached commit

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git bisect は何をしますか。

コミットの範囲を半分ずつ絞り、問題が最初に入ったコミットを見つけます。終わったらgit bisect resetが必要で、忘れるとブランチのないコミットに留まったままになります。

Q. どう打ちますか。

git bisect start <bad> <good> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-bisect