git-commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git 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 #42

Commit Types

提交类型

GitmojiTypePurpose
feat
New feature
🐛
fix
Bug fix
📝
docs
Documentation only
💄
style
Formatting/style (no logic)
♻️
refactor
Code refactor (no feature/fix)
⚡️
perf
Performance improvement
test
Add/update tests
🏗️
build
Build system/dependencies
👷
ci
CI/config changes
🔧
chore
Maintenance/misc
⏪️
revert
Revert commit
Gitmoji类型用途
feat
新功能
🐛
fix
修复Bug
📝
docs
仅修改文档
💄
style
格式/样式调整(无逻辑变更)
♻️
refactor
代码重构(无新功能/修复)
⚡️
perf
性能优化
test
添加/更新测试
🏗️
build
构建系统/依赖变更
👷
ci
CI/配置变更
🔧
chore
维护/杂项任务
⏪️
revert
回滚提交

Additional Gitmoji (use with closest type)

额外Gitmoji(匹配最接近的类型使用)

GitmojiMeaningType
🔒️Security fix
fix
🚀Deploy
chore
🎨Improve structure/format
refactor
🔥Remove code/files
chore
🚑️Critical hotfix
fix
Add dependency
build
Remove dependency
build
🔧Add/update config
chore
🗃️Database changes
feat
📦️Update compiled/packages
build
🚚Move/rename resources
chore
♿️Accessibility
feat
🌐Internationalization
feat
🏷️Add/update types
feat
Gitmoji含义类型
🔒️安全修复
fix
🚀部署
chore
🎨改进结构/格式
refactor
🔥删除代码/文件
chore
🚑️紧急热修复
fix
添加依赖
build
移除依赖
build
🔧添加/更新配置
chore
🗃️数据库变更
feat
📦️更新编译包/依赖包
build
🚚移动/重命名资源
chore
♿️无障碍优化
feat
🌐国际化
feat
🏷️添加/更新类型
feat

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 responses

Body Format

正文格式

Use Gitmoji shortcodes (
:emoji:
) as bullet prefixes in the body to describe individual changes:
- :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 logic

Workflow

工作流程

1. Analyze changes

1. 分析变更

bash
undefined
bash
undefined

Check 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
undefined
git diff
undefined

2. Stage files if needed

2. 按需暂存文件

bash
undefined
bash
undefined

Stage 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
undefined
bash
undefined

Single 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
    GoogleAuthProvider
    with PKCE
  • :lock: add CSRF token validation
Closes #42 EOF )"
undefined
git commit -m "$(cat <<'EOF' ✨ feat(auth): add OAuth2 login flow
  • :sparkles: implement
    GoogleAuthProvider
    with PKCE
  • :lock: add CSRF token validation
Closes #42 EOF )"
undefined

Best Practices

最佳实践

  • One logical change per commit
  • Reference issues:
    Closes #123
    ,
    Refs #456
  • Co-author: append
    Co-Authored-By:
    footer when applicable
  • 每次提交对应一个逻辑变更
  • 引用问题:
    Closes #123
    Refs #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分支
  • 若提交因钩子验证失败,修复后创建新提交(不要修改原有提交)