一分为二
- 作者仓库星标 2,380
- 许可证 MIT
- 作者仓库 dotfiles
- 领域
- 工程开发
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @ryanb · MIT
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 命令执行
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
git bisect reset
第 1 步:确保工作树干净
检查是否存在暂存或未暂存的更改。如果有,请停止并告诉用户在二分之前他们需要一个干净的工作树,因为 git bisect 会检查较旧的提交。如果输出非空,则停止并要求用户首先提交或存储他们的更改。
第二步:确定测试命令
使用`$ARGUMENTS`了解用户想要测试什么。这应该描述当前提交失败的命令或检查。确定要运行的确切 shell 命令。
步骤 3:验证当前提交是否错误
在当前提交 (HEAD) 上运行测试命令。如果通过(退出 0),则停止并告诉用户 — 当前提交没有表现出失败,因此没有什么可以平分的。
第四步:找到一个好的提交
开始从 HEAD 开始向后搜索,以 10 次提交为一步,找到测试通过的提交。运行测试命令。如果仍然失败,请返回另外 10 次提交(从当前位置开始的`HEAD~10`)。重复直到:找到一个通过的提交,或者您已经返回 100 多个提交而没有找到一个通过的提交 - 停止并向用户寻求指导(可能是一个已知良好的提交 SHA)。找到好的提交后,记下其 SHA。
第 5 步:运行 git bisect
首先返回到原始分支,然后开始二分:Git 将签出中间提交。对其运行测试命令: 如果测试失败 → `git bisect bad` 如果测试通过 → `git bisect good` 重复直到 git 报告第一个错误提交。
第6步:记录结果并清理
保存第一个错误的提交 SHA 和消息。然后重置:
第7步:报告
告诉用户第一个错误的提交,包括: 提交 SHA 提交消息 提交作者和日期 提交摘要 `git show --stat`,以便他们可以看到哪些文件发生了更改
# 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`
- 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:
```bash
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 --stat` of the commit so they can see which files changed
章节与文件索引
按说明文件中的顺序排列。
第 1 步:确保工作树干净
第二步:确定测试命令
步骤 3:验证当前提交是否错误
第四步:找到一个好的提交
第 5 步:运行 git bisect
文件/命令 -> git bisect · $ARGUMENTS · HEAD~10 · git bisect bad · git bisect good · git show --stat
内容校验值 -> e3439ad7e889
当前原文的自动摘译,尚未人工审校。
步骤 3:验证当前提交是否错误
在当前提交(HEAD)上运行测试命令。如果通过(退出 0),则停止并告诉用户 — 当前提交没有表现出失败,因此没有什么可以平分的。