commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit Changes

提交变更

Flags

可选参数

FlagEffect
--staged
Diff staged changes (
git diff --cached
). Default.
--unstaged
Diff unstaged changes (
git diff
).
--conventional
Conventional commit message (
type: description
). Default.
--simple
Plain-English one-liner, no conventional formatting.
--verify
Run hooks. Off by default; without it, the commit passes
-n
.
No flags →
--staged --conventional
, hooks skipped.
参数作用
--staged
对比已暂存的变更(
git diff --cached
)。默认选项。
--unstaged
对比未暂存的变更(
git diff
)。
--conventional
生成符合规范的提交信息(
type: description
格式)。默认选项。
--simple
生成纯英文单行提交信息,不使用规范格式。
--verify
执行钩子。默认关闭;不使用该参数时,提交会自动带上
-n
无参数时默认启用
--staged --conventional
,并跳过钩子。

Diff-only constraint

仅基于差异的约束

The diff is the only input for the message. Ignore conversation history, review threads, ticket text, and stated rationale unless the same fact appears in the diff. Never write "address review feedback", "as requested", or "implement the plan". Describe the concrete change instead.
提交信息仅以代码差异作为输入。忽略对话历史、评审线程、工单文本及说明理由,除非这些内容的事实在差异中有所体现。绝对不要写入“处理评审反馈”“按要求修改”“执行计划”这类表述,而是要描述具体的变更内容。

Hook behavior

钩子行为

  • Without
    --verify
    : every
    git commit
    command must include
    -n
    .
  • With
    --verify
    : run hooks; never pass
    -n
    or
    --no-verify
    .
If the commit fails, do not switch hook behavior unless the user changes the flags and asks again.
  • 不使用
    --verify
    时:所有
    git commit
    命令必须包含
    -n
    参数。
  • 使用
    --verify
    时:执行钩子;绝对不能添加
    -n
    --no-verify
    参数。
如果提交失败,除非用户修改参数并再次请求,否则不要更改钩子行为。

-m
flag count

-m
参数数量

Use one or two
-m
flags, never three or more. First
-m
is the subject; an optional second
-m
holds the entire body. Git inserts one blank line between them, producing correct subject/body separation. Put all body bullets in that single second
-m
, separated by
\n
(use
$'...'
), never
\n\n
.
bash
git commit -n -m "feat: add auth flow" \
  -m $'- Implement OAuth login\n- Add JWT handling'
Three or more
-m
flags insert a blank line between every bullet. A single
-m
with an embedded body gets bodies dropped. Both are wrong.
使用1个或2个
-m
参数,绝对不能使用3个及以上。第一个
-m
用于指定主题;可选的第二个
-m
用于填写完整正文。Git会在两者之间插入一个空行,实现主题与正文的正确分隔。将所有正文列表项放在单个第二个
-m
中,用
\n
分隔(使用
$'...'
语法),绝对不要用
\n\n
bash
git commit -n -m "feat: add auth flow" \
  -m $'- Implement OAuth login\n- Add JWT handling'
使用3个及以上
-m
参数会在每个列表项之间插入空行。单个
-m
参数中嵌入正文会导致正文被丢弃。这两种方式都是错误的。

Step 1: Diff the changes

步骤1:获取变更差异

  • --staged
    or default:
    git diff --cached | cat
  • --unstaged
    :
    git diff | cat
If empty, stop: "No changes found to commit."
  • 使用
    --staged
    或默认情况:
    git diff --cached | cat
  • 使用
    --unstaged
    git diff | cat
如果差异为空,则停止操作:“未找到可提交的变更。”

Step 2: Analyze the diff

步骤2:分析差异

From the diff alone, identify changed files, change type, and what the diff does: feature, fix, refactor, docs, test, chore, style, or perf.
仅从差异内容出发,识别变更的文件、变更类型以及差异实现的功能:新增功能(feature)、修复(fix)、重构(refactor)、文档(docs)、测试(test)、杂项(chore)、格式调整(style)或性能优化(perf)。

Step 3: Generate the message

步骤3:生成提交信息

Base the message solely on Step 2. Produce:
  • subject
    : first line only.
  • body
    : optional; bullet lines joined by single
    \n
    .
For the chosen style, follow the exact format rules and examples in
./REFERENCE.md
, conventional rules for
--conventional
, simple rules for
--simple
. For
--simple
, emit
subject
only.
完全基于步骤2的结果生成提交信息,需输出:
  • subject
    :仅第一行内容。
  • body
    :可选内容;列表项用单个
    \n
    连接。
根据所选的格式,严格遵循
./REFERENCE.md
中的格式规则和示例:使用
--conventional
时遵循规范格式,使用
--simple
时遵循简单格式。使用
--simple
时,仅输出
subject

Step 4: Commit

步骤4:执行提交

Pass
subject
in the first
-m
,
body
in a second
-m
when present.
  • Without
    --verify
    :
    git commit -n ...
    . Confirm
    -n
    was present.
  • With
    --verify
    :
    git commit ...
    . Confirm neither
    -n
    nor
    --no-verify
    was present.
subject
放入第一个
-m
参数,若存在
body
则放入第二个
-m
参数。
  • 不使用
    --verify
    时:执行
    git commit -n ...
    。需确认已包含
    -n
    参数。
  • 使用
    --verify
    时:执行
    git commit ...
    。需确认未添加
    -n
    --no-verify
    参数。

Step 5: Report

步骤5:反馈结果

Report the message, diff scope, style, hook behavior, and the exact
git commit
command run.
反馈提交信息、差异范围、格式类型、钩子行为以及执行的完整
git commit
命令。