Closed
[Documentation|文档反馈]: commit-msg template #5
lidongshengAdd on  Dec 26, 2025Closed at  Jan 14
lidongsheng
lidongshengCollaborators
Dec 26, 2025 Create

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Document Link(文档链接)

Sample commit message as follows with a few notes:

  • The subject line must follow the format: feat|fix|fixup: module: Short description.
  • Second line must be blank.
  • Avoid using abbreviations or acronyms for verbose description.
  • Signed-off-by directly after the verbose description with one blank line
  • Co-authored-by is optional.
  • Always use English for commit message.
label: module: Short description with first letter uppercase

verbose description:
- Start with a capital letter.
- Use complete sentences.
- Avoid using abbreviations or acronyms.
- Use simple language.
- Do not use jargon or technical terms unless they are defined in the commit message.

Signed-off-by: <account name> <email address>
Co-authored-by: <account name> <email address>

Issues Section(问题文档片段)

N/A

Existing Issues(存在的问题)

likedislike
lidongshenglidongshengCollaborators
Dec 26, 2025 Change title to "[Documentation|文档反馈]: commit-msg template", originally titled "[Documentation|文档反馈]: commit-msg tempalte".
lidongsheng
lidongshengCollaborators
Dec 26, 2025 Comments:

commit-hook 添加中

likedislike
lidongsheng
lidongshengCollaborators
Dec 26, 2025 Comments:

commit-msg hook脚本

#!/usr/bin/env python3
import re
import sys
from pathlib import Path

def fail(msg: str) -> None:
    print(f"ERROR: {msg}", file=sys.stderr)
    print("""
Sample commit message as follows with a few notes:
- The subject line must follow the format: feat|fix|fixup: module: Short description.
- Second line must be blank.
- Avoid using abbreviations or acronyms for verbose description.
- Signed-off-by directly after the verbose description with one blank line
- Co-authored-by is optional.
- Always use English for commit message.

label: module: Short description with first letter uppercase

verbose description:
- Start with a capital letter.
- Use complete sentences.
- Avoid using abbreviations or acronyms.
- Use simple language.
- Do not use jargon or technical terms unless they are defined in the commit message.

Signed-off-by: <account name> <email address>
Co-authored-by: <account name> <email address>
""")
    sys.exit(1)

commit_msg_file = Path(sys.argv[1])
msg = commit_msg_file.read_text(encoding="utf-8", errors="replace")

# English-only (ASCII)
# -------------------------------------------------------------------
lines = []
for line in msg.splitlines():
    line = line.strip()
    try:
        line.encode("ascii")
    except UnicodeEncodeError:
        fail("Commit message must be written in English (ASCII only).")
    if not line.startswith('#'):
        lines.append(line)

if len(lines) < 4:
    fail("Commit message must contain subject, blank line, body, and Signed-off-by.")

# -------------------------------------------------------------------
# Subject line
# feat|fix|fixup: module: Short description
# -------------------------------------------------------------------
subject = lines[0]

subject_re = re.compile(
    r"^(feat|fix|fixup): [a-zA-Z0-9_.-]+: [A-Z][A-Za-z0-9 ,._-]*$"
)

if not subject_re.match(subject):
    fail(
        "Subject must be: feat|fix|fixup: module: Short description "
        "(short description must start with uppercase)."
    )

# -------------------------------------------------------------------
# Second line must be blank
# -------------------------------------------------------------------
if lines[1] != "":
    fail("Second line must be blank.")

# -------------------------------------------------------------------
# Verbose description (at least one non-empty line before Signed-off-by)
# -------------------------------------------------------------------
body_lines = []
signed_off_index = None

for i, line in enumerate(lines[2:], start=2):
    if line.startswith("Signed-off-by:"):
        signed_off_index = i
        break
    body_lines.append(line)

if not any(body_lines):
    fail("Verbose description is required and must not be empty.")

# -------------------------------------------------------------------
# Signed-off-by description (at least one Signed-off-by)
# -------------------------------------------------------------------
if signed_off_index is None:
    fail("Signed-off-by missing")

if lines[signed_off_index - 1] != "":
    fail("Blank line is required before Signed-off-by.")

signed_re = re.compile(
    r"^(Signed-off-by|Co-authored-by): .+ <[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.com>$"
)
for line in lines[signed_off_index:]:
    if line and not signed_re.match(line):
        fail(f"Invalid Signed-off-by or Co-authored-by line format {line}.")
 
likedislike
杨旭杨旭Collaborators
Jan 7 Assign tsungl4 as responsible person
杨旭杨旭Collaborators
Jan 7 Added label: documentation
杨旭杨旭Collaborators
Jan 8 associated Kanban: PyPTO
杨旭杨旭Collaborators
Jan 8 Associated milestone: r0.1.1
杨旭
杨旭Collaborators
Jan 13 Comments:

@tsungl4 建议上述规则还是刷新到文档里吧,便于大家获取。

likedislike
lidongshenglidongshengCollaborators
Jan 14 Associated pull request
CANN-robotCANN-robotCollaborators
Jan 14 Close issue
lidongshenglidongshengCollaborators
Jan 14 Associated pull request
杨旭杨旭Collaborators
Jan 26 changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
Mar 20 Added label: resolved