git-commit-cn
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit 中文提交信息生成
Generate Chinese Git Commit Messages
自动生成符合约定式提交(Conventional Commits)规范的中文 Git 提交信息。
Automatically generate Chinese Git commit messages that comply with the Conventional Commits specification.
默认行为
Default Behavior
必须遵守以下规则:
- ✅ 使用 emoji:每个提交类型必须包含对应的 emoji 图标
- ✅ 拆分提交:将不同类型或不同模块的变更拆分为多个独立提交
- ❌ 禁用 Co-Authored-By:不添加 署名
Co-Authored-By: Claude Sonnet 4.5
Must follow these rules:
- ✅ Use emojis: Each commit type must include the corresponding emoji icon
- ✅ Split commits: Split changes of different types or modules into multiple independent commits
- ❌ Disable Co-Authored-By: Do not add the attribution
Co-Authored-By: Claude Sonnet 4.5
核心工作流程
Core Workflow
1. 分析代码变更
1. Analyze Code Changes
首先检查代码变更情况:
bash
undefinedFirst check the code changes:
bash
undefined查看未暂存的变更
View unstaged changes
git diff
git diff
查看已暂存的变更
View staged changes
git diff --staged
git diff --staged
查看状态
View status
git status
undefinedgit status
undefined2. 确定提交类型和 Emoji
2. Determine Commit Type and Emoji
根据变更内容确定提交类型和对应 emoji(必须使用):
- feat: ✨ 新增功能或特性
- fix: 🐛 修复 bug 或错误
- docs: 📝 仅文档变更
- style: 💄 代码格式调整(不影响功能)
- refactor: ♻️ 代码重构
- perf: ⚡ 性能优化
- test: ✅ 测试相关
- build: 📦 构建系统或依赖变更
- ci: 👷 CI/CD 配置变更
- chore: 🔧 其他杂项变更
详细说明和示例见 references/commit-types.md
Determine the commit type and corresponding emoji based on change content (Mandatory):
- feat: ✨ New feature or functionality
- fix: 🐛 Fix bug or error
- docs: 📝 Documentation-only changes
- style: 💄 Code format adjustments (no functional impact)
- refactor: ♻️ Code refactoring
- perf: ⚡ Performance optimization
- test: ✅ Test-related changes
- build: 📦 Build system or dependency changes
- ci: 👷 CI/CD configuration changes
- chore: 🔧 Other miscellaneous changes
Detailed explanations and examples can be found in references/commit-types.md
3. 生成提交信息
3. Generate Commit Message
格式要求:
<类型>: <emoji> <简短描述>
[可选的详细描述]简短描述规范:
- 使用动词开头: 添加、修复、更新、删除、优化、重构
- 不超过 50 个字符
- 描述做了什么,不是为什么
- 结尾不使用标点符号
示例:
单行提交:
feat: ✨ 添加用户头像上传功能多行提交:
feat: ✨ 添加用户头像上传功能
支持 JPG/PNG/WebP 格式,最大 5MB
自动生成 200x200 和 48x48 缩略图Format Requirements:
<type>: <emoji> <short description>
[Optional detailed description]Short Description Specifications:
- Start with a verb: add, fix, update, delete, optimize, refactor
- No more than 50 characters
- Describe what was done, not why
- No punctuation at the end
Examples:
Single-line commit:
feat: ✨ 添加用户头像上传功能Multi-line commit:
feat: ✨ 添加用户头像上传功能
支持 JPG/PNG/WebP 格式,最大 5MB
自动生成 200x200 和 48x48 缩略图4. 拆分并执行提交
4. Split and Execute Commits
默认必须拆分提交:将不同类型或不同模块的变更分开提交。
使用 HEREDOC 格式提交,确保格式正确:
bash
git commit -m "$(cat <<'EOF'
feat: ✨ 添加用户管理功能
实现用户列表、添加、编辑、删除功能
集成角色权限管理
EOF
)"Mandatory commit splitting by default: Split changes of different types or modules into separate commits.
Use HEREDOC format to commit to ensure correct formatting:
bash
git commit -m "$(cat <<'EOF'
feat: ✨ 添加用户管理功能
实现用户列表、添加、编辑、删除功能
集成角色权限管理
EOF
)"最佳实践
Best Practices
变更拆分(默认行为)
Change Splitting (Default Behavior)
必须将不同类型或不同模块的变更拆分为独立提交,每个提交只做一件事:
✅ 好的做法:
git add src/auth/
git commit -m "feat: ✨ 添加 OAuth2 登录支持"
git add docs/api.md
git commit -m "docs: 📝 更新认证 API 文档"❌ 不好的做法:
git add .
git commit -m "feat: ✨ 添加登录功能和更新文档"Must split changes of different types or modules into independent commits, each commit should do only one thing:
✅ Good practice:
git add src/auth/
git commit -m "feat: ✨ 添加 OAuth2 登录支持"
git add docs/api.md
git commit -m "docs: 📝 更新认证 API 文档"❌ Bad practice:
git add .
git commit -m "feat: ✨ 添加登录功能和更新文档"带作用域的提交
Commits with Scope
对于大型项目,使用作用域标识变更范围:
feat(auth): ✨ 添加双因素认证
fix(ui): 🐛 修复移动端菜单样式
docs(api): 📝 更新用户 API 文档For large projects, use scopes to identify the scope of changes:
feat(auth): ✨ 添加双因素认证
fix(ui): 🐛 修复移动端菜单样式
docs(api): 📝 更新用户 API 文档破坏性变更标记
Breaking Change Markers
如果变更不兼容旧版本,使用 BREAKING CHANGE:
bash
git commit -m "$(cat <<'EOF'
feat: ✨ 重构用户认证 API
从 Session 改为 JWT Token 认证
BREAKING CHANGE: 旧的 /api/login 接口已移除,
请使用新的 /api/auth/token 接口
EOF
)"If changes are incompatible with older versions, use BREAKING CHANGE:
bash
git commit -m "$(cat <<'EOF'
feat: ✨ 重构用户认证 API
从 Session 改为 JWT Token 认证
BREAKING CHANGE: 旧的 /api/login 接口已移除,
请使用新的 /api/auth/token 接口
EOF
)"常见场景
Common Scenarios
新功能开发
New Feature Development
bash
undefinedbash
undefined添加并提交
Add and commit
git add src/features/upload/
git commit -m "feat: ✨ 添加文件批量上传功能"
undefinedgit add src/features/upload/
git commit -m "feat: ✨ 添加文件批量上传功能"
undefinedBug 修复
Bug Fixes
bash
git add src/components/LoginForm.tsx
git commit -m "fix: 🐛 修复登录表单验证码刷新问题"bash
git add src/components/LoginForm.tsx
git commit -m "fix: 🐛 修复登录表单验证码刷新问题"多文件变更(必须拆分)
Multi-file Changes (Must Split)
bash
undefinedbash
undefined功能实现
Feature implementation
git add src/
git commit -m "$(cat <<'EOF'
feat: ✨ 添加用户积分系统
实现积分获取和消费逻辑
添加积分历史记录
EOF
)"
git add src/
git commit -m "$(cat <<'EOF'
feat: ✨ 添加用户积分系统
实现积分获取和消费逻辑
添加积分历史记录
EOF
)"
测试代码
Test code
git add tests/
git commit -m "test: ✅ 添加积分系统单元测试"
git add tests/
git commit -m "test: ✅ 添加积分系统单元测试"
文档更新
Documentation update
git add docs/
git commit -m "docs: 📝 更新积分系统 API 文档"
undefinedgit add docs/
git commit -m "docs: 📝 更新积分系统 API 文档"
undefined依赖更新
Dependency Updates
bash
git add package.json package-lock.json
git commit -m "build: 📦 升级 React 到 18.3.0"bash
git add package.json package-lock.json
git commit -m "build: 📦 升级 React 到 18.3.0"注意事项
Notes
- 提交前检查: 使用 和
git status确认变更内容git diff - 必须拆分提交: 不同类型或不同模块的变更必须分开提交(默认行为)
- 必须使用 emoji: 每个提交信息必须包含对应的 emoji 图标(默认行为)
- 禁用 Co-Author: 不添加 署名(默认行为)
Co-Authored-By - 清晰描述: 让其他人看到 commit 信息就知道做了什么
- 避免通用描述: 不使用"修复 bug"、"更新代码"等模糊描述
- 使用 HEREDOC: 多行提交信息使用 HEREDOC 格式确保正确
- Pre-commit Check: Use and
git statusto confirm change contentgit diff - Mandatory Commit Splitting: Changes of different types or modules must be split into separate commits (default behavior)
- Mandatory Emoji Usage: Each commit message must include the corresponding emoji icon (default behavior)
- Disable Co-Author: Do not add attribution (default behavior)
Co-Authored-By - Clear Description: Let others know what was done just by looking at the commit message
- Avoid Generic Descriptions: Do not use vague descriptions like "fix bug" or "update code"
- Use HEREDOC: Use HEREDOC format for multi-line commit messages to ensure correctness
参考资源
Reference Resources
- references/commit-types.md - 完整的提交类型和示例
- references/commit-types.md - Complete commit types and examples