commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit with Quality Gates

带有质量门禁的Git提交

Enforce code quality before every commit.
在每次提交前强制执行代码质量检查。

Workflow (MANDATORY ORDER)

工作流(必须按顺序执行)

  1. Quality Gates (BLOCKING - must pass)
    bash
    ./scripts/quality-gates.sh
    • Validates >90% test coverage
    • Runs all tests with strict warnings
    • Checks security vulnerabilities
    • Verifies code quality standards
    If quality gates FAIL: STOP. Fix issues before proceeding.
  2. Check Status
    bash
    git status
    git diff --stat
  3. Stage Changes
    bash
    git add -p  # Interactive staging for atomic commits
    # OR
    git add <specific-files>
  4. Create Commit (use message format below)
    bash
    git commit
  5. Sync with Remote
    bash
    git pull --rebase
  6. Handle Conflicts (if any)
    • STOP - DO NOT AUTO-FIX
    • Notify user for manual resolution
    • Only proceed after user confirms resolution
  7. Push
    bash
    git push
  1. 质量门禁(阻塞性检查 - 必须通过)
    bash
    ./scripts/quality-gates.sh
    • 验证测试覆盖率>90%
    • 运行所有测试并开启严格警告
    • 检查安全漏洞
    • 验证代码质量标准
    如果质量门禁未通过:停止操作。在继续之前修复问题。
  2. 检查状态
    bash
    git status
    git diff --stat
  3. 暂存变更
    bash
    git add -p  # 交互式暂存,实现原子提交
    # 或者
    git add <specific-files>
  4. 创建提交(使用下方的信息格式)
    bash
    git commit
  5. 与远程仓库同步
    bash
    git pull --rebase
  6. 处理冲突(如果有)
    • 停止 - 不要自动修复
    • 通知用户进行手动解决
    • 仅在用户确认解决后再继续
  7. 推送
    bash
    git push

Commit Message Format

提交信息格式

type(scope): Brief description (50 chars max)

- Why this change was necessary from user perspective
- What problem it solves or capability it enables
- Reference issue/ticket numbers if applicable
type(scope): 简短描述(最多50字符)

- 从用户角度说明此变更的必要性
- 说明解决的问题或实现的功能
- 如有需要,引用问题/工单编号

Commit Types

提交类型

TypePurpose
feat
New user-facing feature
fix
Bug fix resolving user issue
docs
Documentation changes
refactor
Code restructure (no user-facing changes)
perf
Performance improvement
test
Test additions/changes
chore
Build/dependency updates
类型用途
feat
新增面向用户的功能
fix
修复用户相关的问题
docs
文档变更
refactor
代码重构(无面向用户的变更)
perf
性能优化
test
测试用例新增/修改
chore
构建/依赖更新

Message Rules

信息规则

  • Subject: 50 chars max, capitalized, no period
  • Body: Wrap at 72 chars
  • Use imperative mood: "Add feature" not "Added feature"
  • Explain WHY from user perspective, not WHAT code changed
  • 主题:最多50字符,首字母大写,末尾无句号
  • 正文:每行不超过72字符
  • 使用祈使语气:例如“Add feature”而非“Added feature”
  • 从用户角度解释原因,而非说明代码做了哪些修改

Examples

示例

Good:
feat(search): Add filters to help users find documents faster

Users were spending too much time scrolling through results.
New filters reduce search time by 60% in user testing.

Fixes #123
Bad:
improved stuff
规范示例:
feat(search): 添加筛选器帮助用户更快找到文档

用户此前需要花费大量时间滚动查看结果。
新筛选器在用户测试中将搜索时间缩短了60%。

修复 #123
不规范示例:
改进了一些内容

Atomic Commit Principle

原子提交原则

  • Each commit = ONE logical change
  • Commit must compile and pass tests
  • Use
    git add -p
    for partial staging
  • 每个提交对应一个逻辑变更
  • 提交的代码必须能编译通过并通过测试
  • 使用
    git add -p
    进行部分暂存

Optional Pre-Push Checks

可选的推送前检查

For larger changes:
bash
./scripts/check-doctests.sh
./scripts/check_performance_regression.sh
对于较大的变更:
bash
./scripts/check-doctests.sh
./scripts/check_performance_regression.sh

References

参考资料

  • AGENTS.md - Required Checks Before Commit
  • commit command
  • AGENTS.md - 提交前的必要检查
  • commit 命令