git-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit with Conventional Commits
遵循Conventional Commits规范的Git提交
Overview
概述
Create standardized, semantic git commits using the Conventional Commits specification. Analyze the actual diff to determine appropriate type, scope, and message.
使用Conventional Commits规范创建标准化的语义化git提交。分析实际的diff以确定合适的类型、范围和消息。
Conventional Commit Format
规范提交格式
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]<type>[可选范围]: <描述>
[可选正文]
[可选页脚]Commit Types
提交类型
| Type | Purpose |
|---|---|
| New feature |
| Bug fix |
| Documentation only |
| Formatting/style (no logic) |
| Code refactor (no feature/fix) |
| Performance improvement |
| Add/update tests |
| Build system/dependencies |
| CI/config changes |
| Maintenance/misc |
| Revert commit |
| 类型 | 用途 |
|---|---|
| 新功能 |
| 修复Bug |
| 仅修改文档 |
| 格式/样式调整(无逻辑变更) |
| 代码重构(无新功能/修复) |
| 性能优化 |
| 添加/更新测试 |
| 构建系统/依赖变更 |
| CI/配置变更 |
| 维护/杂项 |
| 回退提交 |
Breaking Changes
重大变更
undefinedundefinedExclamation mark after type/scope
在类型/范围后添加感叹号
feat!: remove deprecated endpoint
feat!: 移除已弃用的端点
BREAKING CHANGE footer
使用BREAKING CHANGE页脚
feat: allow config to extend other configs
BREAKING CHANGE: key behavior changed
extendsundefinedfeat: 允许配置继承其他配置
BREAKING CHANGE: 键的行为已变更
extendsundefinedWorkflow
工作流程
1. Analyze Diff
1. 分析Diff
bash
undefinedbash
undefinedIf files are staged, use staged diff
如果文件已暂存,使用暂存区的diff
git diff --staged
git diff --staged
If nothing staged, use working tree diff
如果没有文件暂存,使用工作区的diff
git diff
git diff
Also check status
同时检查状态
git status --porcelain
undefinedgit status --porcelain
undefined2. Stage Files (if needed)
2. 暂存文件(如有需要)
If nothing is staged or you want to group changes differently:
bash
undefined如果没有文件暂存,或者你想以不同方式分组变更:
bash
undefinedStage specific files
暂存特定文件
git add path/to/file1 path/to/file2
git add path/to/file1 path/to/file2
Stage by pattern
按模式暂存
git add .test.
git add src/components/*
git add .test.
git add src/components/*
Interactive staging
交互式暂存
git add -p
**Never commit secrets** (.env, credentials.json, private keys).git add -p
**绝对不要提交敏感信息**(.env、credentials.json、私钥)。3. Generate Commit Message
3. 生成提交消息
Analyze the diff to determine:
- Type: What kind of change is this?
- Scope: What area/module is affected?
- Description: One-line summary of what changed (present tense, imperative mood, <72 chars)
分析diff以确定:
- 类型:这是哪种类型的变更?
- 范围:哪个区域/模块受到影响?
- 描述:变更的单行摘要(现在时、祈使语气,不超过72个字符)
4. Execute Commit
4. 执行提交
bash
undefinedbash
undefinedSingle line
单行提交
git commit -m "<type>[scope]: <description>"
git commit -m "<type>[范围]: <描述>"
Multi-line with body/footer
多行提交(包含正文/页脚)
git commit -m "$(cat <<'EOF'
<type>[scope]: <description>
<optional body>
<optional footer>
EOF
)"
```git commit -m "$(cat <<'EOF'
<type>[范围]: <描述>
<可选正文>
<可选页脚>
EOF
)"
undefinedBest Practices
最佳实践
- One logical change per commit
- Present tense: "add" not "added"
- Imperative mood: "fix bug" not "fixes bug"
- Reference issues: ,
Closes #123Refs #456 - Keep description under 72 characters
- 每次提交一个逻辑变更
- 使用现在时:用"add"而非"added"
- 使用祈使语气:用"fix bug"而非"fixes bug"
- 关联议题:、
Closes #123Refs #456 - 描述保持在72个字符以内
Git Safety Protocol
Git安全协议
- NEVER update git config
- NEVER run destructive commands (--force, hard reset) without explicit request
- NEVER skip hooks (--no-verify) unless user asks
- NEVER force push to main/master
- If commit fails due to hooks, fix and create NEW commit (don't amend)
- 绝对不要修改git配置
- 绝对不要在未得到明确请求的情况下运行破坏性命令(--force、硬重置)
- 除非用户要求,否则绝对不要跳过钩子(--no-verify)
- 绝对不要强制推送到main/master分支
- 如果提交因钩子失败,修复后创建新的提交(不要修改现有提交)