git-commit-guidelines

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit Guidelines

Git 提交指南

Best practices for writing clear, consistent git commit messages.
编写清晰、一致的 Git 提交信息的最佳实践。

When to Apply

适用场景

Reference these guidelines when:
  • Writing commit messages
  • Reviewing pull requests for commit quality
  • Setting up commit conventions for a new project
在以下场景中参考本指南:
  • 编写提交信息时
  • 审核拉取请求的提交质量时
  • 为新项目设置提交规范时

Rules

规则

RuleSummary
structure
Use subject line + blank line + body format
subject-line
Keep subject under 72 chars, imperative mood, no trailing period
body
Explain what and why, not how
scope
One logical change per commit
规则概述
structure
使用“主题行 + 空行 + 正文”格式
subject-line
主题行控制在72字符以内,使用祈使语气,末尾不加句号
body
说明变更内容和原因,而非实现方式
scope
每次提交对应一个逻辑变更

Quick Reference

快速参考

Structure

结构

Every commit message should have a short subject line. For non-trivial changes, follow with a blank line and a body that explains context.
每条提交信息都应包含简短的主题行。对于非微小变更,主题行后需加空行,再附上说明上下文的正文。

Subject Line

主题行

  • Use imperative mood: "Add feature" not "Added feature"
  • Keep under 72 characters
  • Capitalize the first word
  • Do not end with a period
  • 使用祈使语气:例如用“Add feature”而非“Added feature”
  • 长度控制在72字符以内
  • 首单词大写
  • 末尾不加句号

Body

正文

  • Wrap at 72 characters
  • Explain what changed and why, not how
  • Reference issue numbers when applicable
  • 每行不超过72字符
  • 说明变更内容原因,而非实现方式
  • 适用时关联问题编号

Scope

范围

  • Each commit should represent one logical change
  • Separate refactoring from behavior changes
  • Separate whitespace/formatting fixes from functional changes
  • 每次提交应代表一个逻辑变更
  • 将重构与行为变更分开提交
  • 将空白/格式修复与功能变更分开提交