Skip to content

Bisect

一句话解释

Bisect uses binary 搜索到 查找精确提交那个 introduced bug, 通过测试提交之间 known-好 and known-坏状态.

用大白话说

git bisect performs a binary search through your commit history to find the exact commit that introduced a bug. You tell Git a "坏" commit (where the bug exists) and a "好" commit (where the bug does not exist), and Git checks out the middle commit for you to test.

After testing, you mark the commit as good or bad, and Git narrows the search range by half, checking out the next middle commit. This repeats until Git identifies the first bad commit. For N commits, it takes about log2(N) steps.

Bisect is extremely efficient for finding regressions. You can even automate it with git bisect 运行 <command> — Git runs the command at each step and marks the commit good or bad based on the exit code.

示例

bash
# Start bisect
git bisect start

# Mark current (bad) and a known-good commit
git bisect bad
git bisect good v1.0.0

# Git checks out a middle commit — test it
git bisect good  # or git bisect bad

# When done, Git shows the first bad commit
git bisect reset  # return to original branch

bisect binary-搜索 history 到查找提交那个 introduced bug.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表