git-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit with Gitmoji + Conventional Commits
结合Gitmoji与Conventional Commits的Git提交
Commit Format
提交格式
<Gitmoji> <type>(<scope>)[!]: <subject>
[optional body]
[optional footer(s)]<Gitmoji> <type>(<scope>)[!]: <subject>
[可选正文]
[可选页脚]Example
示例
✨ feat(auth): add OAuth2 login flow
- :sparkles: implement `GoogleAuthProvider` with PKCE
- :lock: add CSRF token validation
Closes #42✨ feat(auth): add OAuth2 login flow
- :sparkles: implement `GoogleAuthProvider` with PKCE
- :lock: add CSRF token validation
Closes #42Commit Types
提交类型
| Gitmoji | 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 |
| Gitmoji | 类型 | 用途 |
|---|---|---|
| ✨ | | 新功能 |
| 🐛 | | 修复Bug |
| 📝 | | 仅修改文档 |
| 💄 | | 格式/样式调整(无逻辑变更) |
| ♻️ | | 代码重构(无新功能/修复) |
| ⚡️ | | 性能优化 |
| ✅ | | 添加/更新测试 |
| 🏗️ | | 构建系统/依赖变更 |
| 👷 | | CI/配置变更 |
| 🔧 | | 维护/杂项任务 |
| ⏪️ | | 回滚提交 |
Additional Gitmoji (use with closest type)
额外Gitmoji(匹配最接近的类型使用)
| Gitmoji | Meaning | Type |
|---|---|---|
| 🔒️ | Security fix | |
| 🚀 | Deploy | |
| 🎨 | Improve structure/format | |
| 🔥 | Remove code/files | |
| 🚑️ | Critical hotfix | |
| ➕ | Add dependency | |
| ➖ | Remove dependency | |
| 🔧 | Add/update config | |
| 🗃️ | Database changes | |
| 📦️ | Update compiled/packages | |
| 🚚 | Move/rename resources | |
| ♿️ | Accessibility | |
| 🌐 | Internationalization | |
| 🏷️ | Add/update types | |
| Gitmoji | 含义 | 类型 |
|---|---|---|
| 🔒️ | 安全修复 | |
| 🚀 | 部署 | |
| 🎨 | 改进结构/格式 | |
| 🔥 | 删除代码/文件 | |
| 🚑️ | 紧急热修复 | |
| ➕ | 添加依赖 | |
| ➖ | 移除依赖 | |
| 🔧 | 添加/更新配置 | |
| 🗃️ | 数据库变更 | |
| 📦️ | 更新编译包/依赖包 | |
| 🚚 | 移动/重命名资源 | |
| ♿️ | 无障碍优化 | |
| 🌐 | 国际化 | |
| 🏷️ | 添加/更新类型 | |
Subject Line Rules
主题行规则
- Imperative mood, present tense: "add" not "added"
- Lowercase, no period at end
- Max 50 characters
- Wrap code references in backticks
- Focus on WHY, not WHAT
- 使用祈使语气、现在时态:用“add”而非“added”
- 小写结尾,句末无句号
- 最多50个字符
- 代码引用用反引号包裹
- 聚焦于“为什么做”,而非“做了什么”
Breaking Changes
破坏性变更
♻️ refactor(api)!: change response envelope format
BREAKING CHANGE: `data` key renamed to `result` in all API responses♻️ refactor(api)!: change response envelope format
BREAKING CHANGE: `data` key renamed to `result` in all API responsesBody Format
正文格式
Use Gitmoji shortcodes () as bullet prefixes in the body to describe individual changes:
:emoji:- :sparkles: add new endpoint
- :bug: fix null pointer in handler
- :recycle: extract shared validation logic在正文中使用Gitmoji短代码()作为项目符号前缀,描述各项具体变更:
:emoji:- :sparkles: add new endpoint
- :bug: fix null pointer in handler
- :recycle: extract shared validation logicWorkflow
工作流程
1. Analyze changes
1. 分析变更
bash
undefinedbash
undefinedCheck what's staged vs unstaged
查看已暂存与未暂存的文件状态
git status --porcelain
git status --porcelain
View staged diff (preferred)
查看已暂存的差异(推荐)
git diff --staged
git diff --staged
View unstaged diff if nothing staged
若无可暂存内容,查看未暂存的差异
git diff
undefinedgit diff
undefined2. Stage files if needed
2. 按需暂存文件
bash
undefinedbash
undefinedStage specific files (preferred over git add -A)
暂存指定文件(比git add -A更推荐)
git add path/to/file1 path/to/file2
git add path/to/file1 path/to/file2
Stage by pattern
按模式暂存文件
git add src/components/*
Never stage secrets (.env, credentials, private keys).git add src/components/*
切勿暂存敏感信息(.env文件、凭证、私钥)。3. Determine commit attributes
3. 确定提交属性
From the diff, determine:
- Gitmoji + Type: What kind of change?
- Scope: What module/area? (optional but preferred)
- Breaking: Does it break existing API/behavior?
- Subject: One-line summary focusing on WHY
根据差异内容,确定:
- Gitmoji + 类型:变更属于什么类型?
- 范围:涉及哪个模块/区域?(可选但推荐)
- 破坏性:是否会破坏现有API/行为?
- 主题:聚焦于“为什么做”的单行摘要
4. Commit
4. 执行提交
bash
undefinedbash
undefinedSingle line
单行提交
git commit -m "✨ feat(auth): add OAuth2 login flow"
git commit -m "✨ feat(auth): add OAuth2 login flow"
Multi-line with body
多行提交(包含正文)
git commit -m "$(cat <<'EOF'
✨ feat(auth): add OAuth2 login flow
- :sparkles: implement with PKCE
GoogleAuthProvider - :lock: add CSRF token validation
Closes #42
EOF
)"
undefinedgit commit -m "$(cat <<'EOF'
✨ feat(auth): add OAuth2 login flow
- :sparkles: implement with PKCE
GoogleAuthProvider - :lock: add CSRF token validation
Closes #42
EOF
)"
undefinedBest Practices
最佳实践
- One logical change per commit
- Reference issues: ,
Closes #123Refs #456 - Co-author: append footer when applicable
Co-Authored-By:
- 每次提交对应一个逻辑变更
- 引用问题:、
Closes #123Refs #456 - 合作提交:若适用,添加页脚
Co-Authored-By:
Git Safety
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、hard reset)
- 除非用户要求,否则切勿跳过钩子(--no-verify)
- 切勿强制推送到main/master分支
- 若提交因钩子验证失败,修复后创建新提交(不要修改原有提交)