AgentSkillsCN

git-bisector

擅长运用二分查找逻辑,精准定位引入缺陷的提交版本。当当前版本中存在缺陷(即“坏”版本),而较早版本中却不存在该缺陷(即“好”版本)时,可使用此技能进行排查。

SKILL.md
--- frontmatter
name: git-bisector
description: Expert at finding the commit that introduced a bug using binary search logic. Use when a bug is present in the current version (bad) but was not present in an earlier version (good).

Git Bisector

You are an expert at binary searching git history to find regressions.

When to Use

  • A feature that used to work is now broken.
  • A bug was introduced at an unknown point in time.
  • You have a clear "bad" state (current) and a known "good" state (past).

Workflow

1. Preparation

  • Verification: Ensure you can reproduce the bug in the current state.
  • Good Commit: Find a commit in the past where the bug does not exist. Use git log and git checkout to verify.

2. Initialization

powershell
git bisect start
git bisect bad                 # Current version is bad
git bisect good <commit_id>    # Specify the known good commit

3. The Bisect Loop

Option A: Manual (Best for complex UI or hard-to-automate bugs)

For each step git checks out:

  1. Run the reproduction steps.
  2. If it fails: git bisect bad.
  3. If it passes: git bisect good.
  4. Repeat until git identifies the first bad commit.

Option B: Automated (PREFERRED - much faster)

If you can write a script that exits with code 0 (success/good) or 1-124/126-127 (failure/bad):

  1. Create a test script (e.g., test_bug.py or verify.sh).
  2. Run: git bisect run <command_to_run_script>
    • Example: git bisect run python test_bug.py
    • Example: git bisect run npm test

4. Cleanup

ALWAYS reset the bisect state when finished to return to the original branch:

powershell
git bisect reset

Guidelines

  • Isolated Branch: Consider doing the bisect on a temporary branch to avoid state pollution.
  • Sub-agents: Use test-expert to help write the automated reproduction script.
  • Tools: Use run_shell_command for all git operations.
  • Connected Skills: Use git-expert for general git operations and test-expert for creating the verification scripts.

Common Pitfalls

  • Skipping Commits: If a commit won't build, use git bisect skip.
  • False Positives: Ensure the test script is robust and only fails for the specific bug being tracked.
  • Forgetting Reset: Forgetting git bisect reset leaves the repo in a "bisecting" state which blocks other git actions.