commit-sentinel
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese🛡️ Skill: Commit Sentinel (v2.1.0)
🛡️ 技能:提交哨兵(v2.1.0)
Executive Summary
执行摘要
The is the guardian of repository health and historical clarity. In 2026, where AI agents generate thousands of lines of code daily, the role of the sentinel is critical to prevent "History Pollution" and "Type Decay." This skill enforces a rigorous 4-step validation protocol, promotes surgical history sculpting via rebasing, and leverages automated hooks to ensure that only elite-level code reaches the main branch.
commit-sentinelThe 是代码仓库健康度和提交历史清晰度的守护者。在2026年,AI Agent 每天会生成数千行代码,哨兵的作用对于防范「历史污染」和「类型退化」至关重要。本技能执行一套严格的4步校验协议,通过变基实现精准的提交历史梳理,并借助自动化钩子确保只有高质量的代码才能合入主干分支。
commit-sentinel📋 Table of Contents
📋 目录
🛡️ The 4-Step Validation Protocol
🛡️ 4步校验协议
Before every commit, the Sentinel MUST execute:
- Surgical Diff Review: to verify every line.
git diff --cached- Filter: Remove all ,
console.log(unless planned), and debug artifacts.TODO
- Filter: Remove all
- Strict Type Audit: (Mandatory).
bun x tsc --noEmit- Standard: ZERO type errors allowed in the entire workspace.
- Linter Enforcement: .
bun run lint- Standard: Adherence to the project's formatting and security rules.
- Logical Atomicity: Ensure the commit does exactly ONE thing.
- Check: If the diff covers multiple features/fixes, use to split.
git add -p
- Check: If the diff covers multiple features/fixes, use
每次提交前,哨兵必须执行以下操作:
- 精准差异审查:执行 校验每一行改动
git diff --cached- 过滤规则:移除所有 、
console.log(除非已纳入规划)以及调试代码片段TODO
- 过滤规则:移除所有
- 严格类型审计:执行 (强制要求)
bun x tsc --noEmit- 标准:整个工作区不允许存在任何类型错误
- Lint 规则强制校验:执行
bun run lint- 标准:符合项目的格式化及安全规则要求
- 逻辑原子性校验:确保本次提交仅做一件事
- 检查方式:如果差异覆盖多个功能/修复,使用 拆分提交
git add -p
- 检查方式:如果差异覆盖多个功能/修复,使用
🚫 The "Do Not" List (Anti-Patterns)
🚫 「禁止」操作列表(反模式)
| Anti-Pattern | Why it fails in 2026 | Modern Alternative |
|---|---|---|
| Bypasses safety hooks. | Fix the underlying issue. |
| Useless for forensics/AI context. | Use Conventional Commits. |
| Pushed Rebases | Breaks the team's local history. | Only rebase local branches. |
| Massive "Cleanup" Commits | Makes | Use Atomic, Incremental Changes. |
| SHA-1 Assumptions | Security risk in modern Git. | Prepare for SHA-256 (Git 3.0). |
| 反模式 | 2026年不适用的原因 | 现代替代方案 |
|---|---|---|
| 绕过安全钩子 | 修复触发校验失败的底层问题 |
| 对问题追溯/AI上下文毫无意义 | 使用 Conventional Commits 规范 |
| 推送已变基的公共分支 | 破坏团队本地提交历史 | 仅对本地分支执行变基操作 |
| 大规模「清理」提交 | 导致 | 采用原子化、增量式改动 |
| 依赖SHA-1的假设 | 现代Git中的安全风险 | 做好 SHA-256 (Git 3.0) 适配准备 |
📝 Conventional Commits 2026
📝 Conventional Commits 2026 规范
We follow the strictly typed commit standard:
- A new feature.
feat(scope): - A bug fix.
fix(scope): - No feature or bug change.
refactor(scope): - Performance improvements.
perf(scope): - Internal tools/config.
chore(scope): - Documentation only.
docs(scope):
Structure:
text
type(scope)!: short description (max 50 chars)
Detailed body explaining WHY this change was made.
Wrapped at 72 chars.
BREAKING CHANGE: [details]
Resolves #123我们遵循严格类型化的提交标准:
- 新增功能
feat(scope): - 修复Bug
fix(scope): - 无功能或Bug改动的代码重构
refactor(scope): - 性能优化
perf(scope): - 内部工具/配置改动
chore(scope): - 仅文档改动
docs(scope):
提交结构:
text
type(scope)!: short description (max 50 chars)
Detailed body explaining WHY this change was made.
Wrapped at 72 chars.
BREAKING CHANGE: [details]
Resolves #123🔨 History Sculpting (Interactive Rebase)
🔨 提交历史梳理(交互式变基)
The Sentinel never pushes messy local history.
bash
undefined哨兵永远不会推送混乱的本地提交历史。
bash
undefinedClean up the last 3 local commits before pushing
推送前清理最近3条本地提交
git rebase -i HEAD~3
*Use `squash` to combine small "fix" commits into a single "feat" or "fix".*
---git rebase -i HEAD~3
*使用 `squash` 将小型「fix」提交合并为单个「feat」或「fix」提交。*
---🔍 Forensic Validation (Git Bisect)
🔍 问题追溯校验(Git Bisect)
When a bug appears, find the source with binary search.
bash
git bisect start
git bisect bad HEAD
git bisect good [last_known_good_tag]出现Bug时,通过二分查找定位问题来源。
bash
git bisect start
git bisect bad HEAD
git bisect good [last_known_good_tag]Automate with:
自动化执行:
git bisect run bun test
---git bisect run bun test
---🚀 Git 3.0 Readiness
🚀 Git 3.0 适配准备
- SHA-256: Transitioning away from SHA-1 for collision resistance.
- Rust Core: Native speed for monorepo operations.
- Push Protection: Automated secret detection in the commit loop.
- SHA-256:逐步弃用SHA-1以提升抗碰撞能力
- Rust 核心:原生提速,适配 monorepo 操作
- 推送防护:在提交流程中自动检测密钥信息
📖 Reference Library
📖 参考库
Detailed deep-dives into Git excellence:
- Git Forensics: Regressions and bisecting.
- Advanced Rebasing: interactive mode and autosquash.
- Git 3.0 Guide: SHA-256 and Rust integration.
- Hook Automation: Husky, Lefthook, and Pre-commit.
Updated: January 22, 2026 - 17:50
Git 最佳实践深度指南:
- Git 问题追溯:回归问题与二分查找
- 高级变基操作:交互式模式与自动压缩
- Git 3.0 指南:SHA-256 与 Rust 集成
- 钩子自动化:Husky、Lefthook 与 Pre-commit
更新时间:2026年1月22日 17:50