Bisect 代码验证
- 作者仓库星标 2,380
- 许可证 MIT
- 作者仓库 dotfiles
bisect — Find the First Bad Commit
Use git bisect to binary-search through commit history and find the first commit that introduced a failure.
Step 1: Ensure clean working tree
Check that there are no staged or unstaged changes. If there are, stop and tell the user they need a clean working tree before bisecting, since git bisect checks out older commits.
git status --porcelain
If the output is non-empty, stop and ask the user to commit or stash their changes first.
Step 2: Determine the test command
Use $ARGUMENTS to understand what the user wants to test. This should describe a command or check that fails on the current commit. Determine the exact shell command to run.
Step 3: Verify the current commit is bad
Run the test command on the current commit (HEAD). If it passes (exits 0), stop and tell the user — the current commit doesn't exhibit the failure, so there's nothing to bisect.
Step 4: Find a good commit
Start searching backwards from HEAD in steps of 10 commits to find a commit where the test passes.
git stash --include-untracked -q 2>/dev/null; true
git checkout HEAD~10 --quiet
Run the test command. If it still fails, go back another 10 commits (HEAD~10 from the current position). Repeat until either:
- A passing commit is found, or
- You've gone back 100+ commits without finding a passing one — stop and ask the user for guidance (maybe a known-good commit SHA).
Once a good commit is found, note its SHA.
Step 5: Run git bisect
Return to the original branch first, then start bisecting:
git checkout - --quiet
git bisect start
git bisect bad
git bisect good <good-commit-sha>
Git will check out a middle commit. Run the test command on it:
- If the test fails →
git bisect bad - If the test passes →
git bisect good
Repeat until git reports the first bad commit.
Step 6: Record the result and clean up
Save the first bad commit SHA and message. Then reset:
git bisect reset
Step 7: Report
Tell the user the first bad commit, including:
- The commit SHA
- The commit message
- The commit author and date
- A brief
git show --statof the commit so they can see which files changed
- 流狐分类
- 工程开发
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @ryanb · MIT
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 需简单配置
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- Shell 执行
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
# Step 6: Record the result and clean up
git bisect reset Check that there are no staged or unstaged changes. If there are, stop and tell the user they need a clean working tree before bisecting, since git bisect checks out older commits. If the output is non-empty, stop and ask the user to commit or stash their…
Use $ARGUMENTS to understand what the user wants to test. This should describe a command or check that fails on the current commit. Determine the exact shell command to run.
Run the test command on the current commit (HEAD). If it passes (exits 0), stop and tell the user — the current commit doesn't exhibit the failure, so there's nothing to bisect.
Start searching backwards from HEAD in steps of 10 commits to find a commit where the test passes. Run the test command. If it still fails, go back another 10 commits (HEAD~10 from the current position). Repeat until either:
Return to the original branch first, then start bisecting: Git will check out a middle commit. Run the test command on it: If the test fails → git bisect bad
Save the first bad commit SHA and message. Then reset:
# bisect — Find the First Bad Commit
Use `git bisect` to binary-search through commit history and find the first commit that introduced a failure.
## Step 1: Ensure clean working tree
Check that there are no staged or unstaged changes. If there are, **stop and tell the user** they need a clean working tree before bisecting, since git bisect checks out older commits.
```bash
git status --porcelain
```
If the output is non-empty, stop and ask the user to commit or stash their changes first.
## Step 2: Determine the test command
Use `$ARGUMENTS` to understand what the user wants to test. This should describe a command or check that fails on the current commit. Determine the exact shell command to run.
## Step 3: Verify the current commit is bad
Run the test command on the current commit (HEAD). If it **passes** (exits 0), stop and tell the user — the current commit doesn't exhibit the failure, so there's nothing to bisect.
## Step 4: Find a good commit
Start searching backwards from HEAD in steps of 10 commits to find a commit where the test passes.
```bash
git stash --include-untracked -q 2>/dev/null; true
git checkout HEAD~10 --quiet
```
Run the test command. If it still fails, go back another 10 commits (`HEAD~10` from the current position). Repeat until either:
- A passing commit is found, or
- You've gone back 100+ commits without finding a passing one — stop and ask the user for guidance (maybe a known-good commit SHA).
Once a good commit is found, note its SHA.
## Step 5: Run git bisect
Return to the original branch first, then start bisecting:
```bash
git checkout - --quiet
git bisect start
git bisect bad
git bisect good <good-commit-sha>
```
Git will check out a middle commit. Run the test command on it:
- If the test **fails** → `git bisect bad`
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> Step 1: Ensure clean working tree → Step 2: Determine the test command → Step 3: Verify the current commit is bad → Step 4: Find a good commit → Step 5: Run git bisect → Step 6: Record the result and clean up
要点 -> stop and tell the user · passes · fails · Use git bisect to binary-search through commit history and find the first commit that introduced a failure. · Check that there are no staged or unstaged changes. · If the output is non-empty, stop and ask the user to commit or stash their changes first. · Use $ARGUMENTS to understand what the user wants to test. · Run the test command on the current commit (HEAD).
文件/命令 -> git bisect · $ARGUMENTS · HEAD~10 · git bisect bad · git bisect good · git show --stat
内容 SHA-256 -> e3439ad7e889
方法与流程
适用与边界
原文中的明确线索
git bisect、$ARGUMENTS、HEAD~10、git bisect bad、git bisect good、git show --stat