The core goal is to state this change clearly with one accurate, concise, traceable message.
Process
-
Prioritize understanding the purpose and scope of the change from the current session. When information is insufficient, only read what is needed to determine the message,
git statusand the relevant diff; do not expand the investigation just to re-understand known changes. -
When the commit message involves business terminology, prioritize the unified terminology already known from the current session.
-
Generate the commit message in the following format:
<type>[(scope)]: <summary> [body] [footer]
- Choose the type closest to the purpose of the change:
featnew feature;fixbug fix;refactorrefactor;perfperformance optimization;docsdocumentation;testtests;buildbuild or dependencies;cicontinuous integration;styleformatting adjustments that do not affect logic;choreother maintenance;revertrevert commit.
scopeUse only when it can reliably point to a module, component, or business domain; omit it when it cannot be accurately categorized.summaryUse the imperative mood and directly describe the result brought by the change; do not add a period, and keep the title within 72 characters. Follow terminology already established by the user and in the code, and do not invent naming.- Add
bodyonly when the title alone cannot clearly explain the content or reason for the change; explain "what was changed and why it was changed", and do not restate code implementation details. - For breaking changes, add
!after the type, and write it infooterstated inBREAKING CHANGE: <影响>. Use related information as neededRefs: #123。 - One message should express only one logical change. When a change contains multiple independent purposes, it should be split into separate commits.
Execution Boundaries
- When the user only asks to "write a commit message" or "review a message", only output the result and do not perform Git writes.
- When the user asks to "commit", only stage changes related to the current session. If the ownership of already staged content is unclear, use the question tool to confirm before writing.
- Do not automatically push.
Examples
fix(订单): 处理空订单号时不再崩溃
feat(api)!: 使用信封格式包装审批响应
统一响应元数据的承载方式。
BREAKING CHANGE: 客户端必须从 data 字段读取原响应内容