git bisect で不具合を入れたコミットを安全に特定
Git bisect assistant: find the commit that broke it, safely
テストコマンドを指定するだけで git bisect run を安全に実行し、各ステップを記録して、元のブランチに必ず戻したうえで最初の不具合コミットと変更ファイルを報告します。
できること
「前は動いていたのに、いつから壊れた?」を、コミット履歴をさかのぼって自動で特定します。
- 指定したテストコマンド(成功=正常、失敗=不具合、終了コード 125=判定不能)で
git bisect runを実行 - 正常だったコミット(good)を指定しない場合は、直近のタグや main/master との分岐点を候補として自動検出
- 開始前に「good で成功し、bad で失敗するか」を確認し、テストが不具合を再現できないときは止める
- 各ステップ(コミット・終了コード・判定・所要秒数)を JSONL ログに記録
- 1 回ごとのタイムアウト(プロセスツリーごと停止)と、タイムアウト時の扱い(スキップ/不具合)を指定可能
- エラーや Ctrl+C でも必ず
git bisect resetして元のブランチに戻す - 最初の不具合コミットを作者・日付・件名・変更ファイル一覧(diff stat)つきで報告
使い方
python scripts/bisect_run.py --detect-only
python scripts/bisect_run.py --cmd "python -m pytest tests/test_cart.py -q" --good v1.4.0 --timeout 300
エージェントに「v1.4 では動いていたテストがいつから落ちるようになったか調べて」と頼むと、コマンドを決めて実行し、原因らしい変更を説明します。Claude・Codex・Hermes Agent・Cursor で使えます。
必要な環境
- Python 3(標準ライブラリのみ)
- Git
注意点
- 追跡中のファイルに未コミットの変更があるときや、すでに bisect 中のときは開始しません(stash などを勝手に行いません)。
- コミット・push・ファイル削除は行いません。ただしテストコマンドは古いコミットで何度も実行されるので、本番環境に影響するコマンドは使わないでください。
- テストが不安定(たまに落ちる)だと、誤ったコミットを指すことがあります。
- Windows ではコマンドが cmd.exe で実行されるため、引用符はダブルクォートを使ってください。
English description
Runs git bisect run safely with your test command, logs every step, always restores the original branch, and reports the first bad commit with its diff stat.
What it does
Finds the commit that broke something by walking the history automatically.
- Runs
git bisect runwith your test command (exit 0 = good, non-zero = bad, 125 = cannot test / skip) - If no good ref is given, suggests one automatically: the latest reachable tag or the merge-base with main/master
- Before bisecting, checks that the command passes on good and fails on bad, and stops if the test does not reproduce the bug
- Logs every step (commit, exit code, verdict, seconds) to a JSONL file
- Per-run timeout that kills the whole process tree, counted as skip or bad as you choose
- Always runs
git bisect resetback to the original branch, also on errors and Ctrl+C - Reports the first bad commit with author, date, subject and diff stat
How to use
python scripts/bisect_run.py --detect-only
python scripts/bisect_run.py --cmd "python -m pytest tests/test_cart.py -q" --good v1.4.0 --timeout 300
Ask the agent something like "this test passed in v1.4, find the commit that broke it". It chooses the command, runs the bisect and explains the likely cause. Works with Claude, Codex, Hermes Agent and Cursor.
Requirements
- Python 3 (standard library only)
- Git
Caveats
- It will not start when tracked files have uncommitted changes or a bisect is already running, and it never stashes on its own.
- It never commits, pushes or deletes files, but your test command runs on many old commits, so do not use commands that touch production systems.
- Flaky tests can make bisect point at the wrong commit.
- On Windows the command runs through cmd.exe, so use double quotes.
インストール方法
- ダウンロードしたZIPを展開します(中に
git-bisect-assistant/フォルダとSKILL.mdがあります)。 - フォルダごと、使うエージェントのスキル置き場にコピーします。
- Claude:
~/.claude/skills/(プロジェクト単位なら.claude/skills/) - Hermes Agent:
~/.hermes/skills/ - Codex:
~/.agents/skills//Cursor:~/.cursor/skills/ - Claude アプリ(claude.ai):「カスタマイズ → スキル」からZIPをアップロード
- Claude:
- エージェントを再起動し、スキル一覧に表示されることを確認します。
出品者
Skills that make everyday developer work faster and safer: Git, testing, APIs and security.
出品スキル 8 件