commit-zh

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

中文 Git 提交

Chinese Git Commit

分析暂存/未暂存变更,生成中文 conventional commit message,主 agent 全程执行。
Analyze staged/unstaged changes and generate Chinese conventional commit messages, executed entirely by the main agent.

Conventional Commit 格式

Conventional Commit Format

<type>[(scope)]: <中文描述>

[可选正文]

[可选脚注]
type/scope 始终英文,subject/body/footer 中文。
<type>[(scope)]: <Chinese description>

[Optional body]

[Optional footer]
type/scope must always be in English, subject/body/footer in Chinese.

Commit Types

Commit Types

Type用途
feat
新功能
fix
修复 bug
docs
文档变更
style
格式/样式
refactor
重构
perf
性能优化
test
测试相关
build
构建系统/依赖
ci
CI/配置变更
chore
维护/杂项
revert
回退提交
TypePurpose
feat
New feature
fix
Bug fix
docs
Documentation changes
style
Formatting/style changes
refactor
Code refactoring
perf
Performance optimization
test
Testing-related changes
build
Build system/dependencies
ci
CI/configuration changes
chore
Maintenance/miscellaneous
revert
Revert a previous commit

工作流

Workflow

1. 检查仓库状态

1. Check Repository Status

bash
git status --porcelain
无变更则停止。
bash
git status --porcelain
Stop if there are no changes.

2. 分析 Diff

2. Analyze Diff

bash
undefined
bash
undefined

有暂存文件用暂存 diff

Use staged diff if there are staged files

git diff --staged
git diff --staged

无暂存用工作区 diff

Use workspace diff if no files are staged

git diff
undefined
git diff
undefined

3. 暂存文件(如需)

3. Stage Files (If Needed)

无暂存时按逻辑分组暂存:
bash
git add path/to/file1 path/to/file2
  • 按逻辑关联分组
  • 禁止暂存可能含密钥的文件(.env、credentials、private keys)
  • 禁止
    git add .
    /
    git add -A
  • 多逻辑单元 → 建议拆分多次提交
Stage files in logical groups when no files are staged:
bash
git add path/to/file1 path/to/file2
  • Group by logical relevance
  • Prohibit staging files that may contain secrets (.env, credentials, private keys)
  • Prohibit
    git add .
    /
    git add -A
  • Multiple logical units → Suggest splitting into multiple commits

4. 生成 Commit Message

4. Generate Commit Message

  • Type:变更类型(英文)
  • Scope:目录/模块名(英文,可省略)
  • Subject:中文摘要,祈使句式,≤72 字符
  • Body
    - 
    列表解释 why/what,≤3 条,每条 ≤72 字符
  • Footer:破坏性变更/issue 引用
  • Type: Change type (English)
  • Scope: Directory/module name (English, optional)
  • Subject: Chinese summary, imperative mood, ≤72 characters
  • Body: List with
    - 
    explaining why/what, ≤3 items, each ≤72 characters
  • Footer: Breaking changes/issue references

格式约束

Format Constraints

  1. Subject ≤72 字符,无句号
  2. Body:subject 后空一行,
    - 
    开头,说明意图和原因
  3. Footer:body 后空一行,git trailer(如
    Closes #123
    ),破坏性变更用
    BREAKING CHANGE: <描述>
    + type 后加
    !
  1. Subject ≤72 characters, no period
  2. Body: Blank line after subject, starts with
    - 
    , explains intent and reason
  3. Footer: Blank line after body, git trailer (e.g.
    Closes #123
    ), use
    BREAKING CHANGE: <description>
    and add
    !
    after type for breaking changes

示例

Examples

text
feat(auth): 添加 OAuth2 登录支持

- 实现 Google 和 GitHub 第三方登录
- 添加用户授权回调处理
- 优化登录状态持久化逻辑

Closes #42
text
feat(api)!: 重新设计认证 API

- 从 session 认证迁移到 JWT
- 更新所有端点签名
- 移除已废弃的登录方式

BREAKING CHANGE: 认证 API 已完全重新设计,所有客户端需更新集成
text
feat(auth): 添加 OAuth2 登录支持

- 实现 Google 和 GitHub 第三方登录
- 添加用户授权回调处理
- 优化登录状态持久化逻辑

Closes #42
text
feat(api)!: 重新设计认证 API

- 从 session 认证迁移到 JWT
- 更新所有端点签名
- 移除已废弃的登录方式

BREAKING CHANGE: 认证 API 已完全重新设计,所有客户端需更新集成

5. 执行或建议拆分

5. Execute or Suggest Splitting

  • 单一逻辑单元:直接提交,无需确认
  • 多逻辑单元:建议拆分,等确认后执行
  • Single logical unit: Commit directly without confirmation
  • Multiple logical units: Suggest splitting, execute after confirmation

6. 执行提交

6. Execute Commit

bash
git commit -m "$(cat <<'EOF'
<type>[(scope)]: <中文描述>

<body>

<footer>
EOF
)"
禁止自动推送。仅本地提交,除非用户明确要求。
bash
git commit -m "$(cat <<'EOF'
<type>[(scope)]: <中文描述>

<body>

<footer>
EOF
)"
Prohibit automatic push. Only commit locally unless explicitly requested by the user.

7. 提交后

7. After Commit

bash
git log --oneline -1
bash
git log --oneline -1

安全协议

Security Protocol

  • 禁止修改 git config
  • 禁止破坏性命令(--force、hard reset)除非用户明确要求
  • 禁止跳过 hooks(--no-verify)除非用户明确要求
  • 禁止提交含密钥/可能含密钥的文件
  • 单一逻辑变更直接提交,多逻辑单元建议拆分后等确认
  • 禁止自动推送,仅本地提交
  • Prohibit modifying git config
  • Prohibit destructive commands (--force, hard reset) unless explicitly requested by the user
  • Prohibit skipping hooks (--no-verify) unless explicitly requested by the user
  • Prohibit committing files containing secrets or potentially containing secrets
  • Commit single logical changes directly; suggest splitting multiple logical units and wait for confirmation
  • Prohibit automatic push, only commit locally