git-commit-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit Workflow
Git 提交工作流
You are an expert in Git commit workflows with structured commit message generation.
Follow this procedure when assisting users with git operations.
您是精通Git提交工作流及结构化提交信息生成的专家。在协助用户进行Git操作时,请遵循以下流程。
Core Principles
核心原则
- Never auto-commit: Always get explicit user confirmation before executing
git commit - Interactive staging: Ask user to stage files if there are any unstaged changes, regardless of staged status
- Structured messages: Generate commit messages following the defined format
- PMS/Issue tracking: Ask for PMS and GitHub Issue numbers, parse them correctly
- 禁止自动提交:执行前必须获得用户的明确确认
git commit - 交互式暂存:无论当前是否有已暂存的变更,只要存在未暂存的变更,就请用户选择要暂存的文件
- 结构化信息:按照指定格式生成提交信息
- PMS/Issue追踪:向用户索要PMS和GitHub Issue编号,并正确解析
Workflow Steps
工作流步骤
Step 1: Check Git Status
步骤1:检查Git状态
When user wants to commit, first check the current git status:
bash
git status --porcelainInterpret the output:
- First column: staged status (=modified,
M=added,A=deleted,D=renamed)R - Second column: working tree status
- Files with no first column: untracked/new files
Present the results to user with file lists separated by:
- Staged files: files with entries in first column (already staged)
- Unstaged files: files with entries in second column (changes in working directory) - includes both new and modified files
Action guidance:
- No staged, no unstaged → Inform user, ask to make changes first
- Has unstaged (regardless of staged status) → Must ask user which files to stage
- No unstaged, has staged → Ready for diff review (skip staging)
当用户想要提交时,首先检查当前Git状态:
bash
git status --porcelain解析输出内容:
- 第一列:暂存状态(=已修改,
M=已添加,A=已删除,D=已重命名)R - 第二列:工作区状态
- 无第一列的文件:未追踪/新建文件
将结果展示给用户,并按以下类别区分文件列表:
- 已暂存文件:第一列有标识的文件(已完成暂存)
- 未暂存文件:第二列有标识的文件(工作区中的变更)——包含新建和修改的文件
操作指引:
- 无已暂存也无未暂存文件 → 告知用户,请先进行代码变更
- 存在未暂存文件(无论是否有已暂存文件) → 必须询问用户要暂存哪些文件
- 无未暂存但有已暂存文件 → 准备进行差异审查(跳过暂存步骤)
Step 2: Stage Files (if needed)
步骤2:暂存文件(如有需要)
User confirms which files to stage. Stage them:
bash
git add <path1> <path2> ...Ask user: "现在请查看暂存区的差异并生成提交信息草稿。"
用户确认要暂存的文件后,执行暂存操作:
bash
git add <path1> <path2> ...询问用户:“现在请查看暂存区的差异并生成提交信息草稿。”
Step 3: Get Staged Diff and Generate Draft
步骤3:获取暂存区差异并生成草稿
Retrieve the staged changes:
bash
git diff --stagedAnalyze the diff and generate a commit message draft following the specified format.
获取已暂存的变更:
bash
git diff --staged分析差异内容,按照指定格式生成提交信息草稿。
Commit Message Format
提交信息格式
Follow this exact structure:
<type>[optional scope]: <english description> [MUST NOT exceed 80 chars]
[English body - optional, max 80 chars per line]
[Chinese body - optional, max 80 chars per line, must pair with English]
Log: [short description in Chinese]
PMS: <BUG-number or TASK-number> or omit this line if user has none
Issue: Fixes #<number> or omit this line if user has none
Influence: [explain impact in Chinese]严格遵循以下结构:
<类型>[可选范围]: <英文描述> [不得超过80字符]
[英文正文 - 可选,每行最多80字符]
[中文正文 - 可选,每行最多80字符,必须与英文正文配对提供]
Log: <中文简短描述>
PMS: <BUG编号或TASK编号> 若无则省略此行
Issue: Fixes #<编号> 若无则省略此行
Influence: <中文描述变更影响>Type Options
类型选项
- : A new feature
feat - : A bug fix
fix - : Documentation only changes
docs - : Changes that do not affect code meaning (formatting, spacing)
style - : Code refactoring without feature changes
refactor - : Performance improvements
perf - : Adding or updating tests
test - : Maintenance tasks (build, deps, etc.)
chore - : CI/CD configuration changes
ci
- : 新增功能
feat - : 修复Bug
fix - : 仅修改文档
docs - : 不影响代码逻辑的变更(格式调整、空格等)
style - : 代码重构,无功能变更
refactor - : 性能优化
perf - : 添加或更新测试
test - : 维护任务(构建、依赖等)
chore - : CI/CD配置变更
ci
Constraints
约束条件
- Body lines must not exceed 80 characters
- English and Chinese body must appear in pairs if provided
- Log should be concise Chinese description
- 正文每行不得超过80字符
- 若提供正文,英文和中文必须配对出现
- Log应为简洁的中文描述
Step 3.1: Handle PMS Number
步骤3.1:处理PMS编号
You MUST ask the user for PMS number. Accept these formats:
- PMS URL: or
https://pms.uniontech.com/task-view-385999.htmlhttps://pms.uniontech.com/bug-view-385999.html - Direct format: or
BUG-123456TASK-123456
Parse the input using your own understanding (no scripts needed):
- If URL contains → extract the number, format as
/task-view-TASK-xxxxxx - If URL contains → extract the number, format as
/bug-view-BUG-xxxxxx - If already in correct format (starting with BUG- or TASK-), use as-is
- If user provides just a number without prefix, ask them which type it is
Examples:
- →
https://pms.uniontech.com/task-view-385999.htmlTASK-385999 - →
https://pms.uniontech.com/bug-view-123456.htmlBUG-123456 - →
TASK-789012TASK-789012
If user explicitly states they have no PMS number, remove the entire line from the commit message.
PMS:必须向用户索要PMS编号。支持以下格式:
- PMS链接:或
https://pms.uniontech.com/task-view-385999.htmlhttps://pms.uniontech.com/bug-view-385999.html - 直接格式:或
BUG-123456TASK-123456
自行解析输入内容(无需脚本):
- 若链接包含→ 提取编号,格式化为
/task-view-TASK-xxxxxx - 若链接包含→ 提取编号,格式化为
/bug-view-BUG-xxxxxx - 若已为正确格式(以BUG-或TASK-开头) → 直接使用
- 若用户仅提供编号无前缀 → 询问用户编号类型
示例:
- →
https://pms.uniontech.com/task-view-385999.htmlTASK-385999 - →
https://pms.uniontech.com/bug-view-123456.htmlBUG-123456 - →
TASK-789012TASK-789012
若用户明确表示无PMS编号,则从提交信息中移除整个行。
PMS:Step 3.2: Handle GitHub Issue Number
步骤3.2:处理GitHub Issue编号
You MUST ask the user for GitHub Issue number. Accept these formats:
- Issue URL:
https://github.com/owner/repo/issues/183 - Direct format: (for current repo) or
#183(for other repos)owner/repo#183
Parse the input using your own understanding (no scripts needed):
- From URL: extract owner, repo name, and issue number from the path
- From direct input: parse the format
- Determine if it's the current repository:
- Run to check the current repo name
git remote get-url origin - If the issue's repo matches, use format
#<number> - If different, use format
owner/repo#<number>
- Run
- If just a number without , infer it's for current repo:
##183
Examples:
- For repo :
Pimzino/spec-workflow-mcp- →
https://github.com/Pimzino/spec-workflow-mcp/issues/183#183 - →
#183#183 - →
183#183 - →
https://github.com/other/repo/issues/42other/repo#42
If user explicitly states they have no Issue number, remove the entire line from the commit message.
Issue:必须向用户索要GitHub Issue编号。支持以下格式:
- Issue链接:
https://github.com/owner/repo/issues/183 - 直接格式:(当前仓库)或
#183(其他仓库)owner/repo#183
自行解析输入内容(无需脚本):
- 从链接中:提取仓库所有者、仓库名称和Issue编号
- 从直接输入中:解析格式
- 判断是否为当前仓库:
- 执行检查当前仓库名称
git remote get-url origin - 若Issue所属仓库与当前仓库匹配,使用格式
#<编号> - 若不匹配,使用格式
owner/repo#<编号>
- 执行
- 若仅提供编号无,默认视为当前仓库的Issue:
##183
示例:
- 对于仓库:
Pimzino/spec-workflow-mcp- →
https://github.com/Pimzino/spec-workflow-mcp/issues/183#183 - →
#183#183 - →
183#183 - →
https://github.com/other/repo/issues/42other/repo#42
若用户明确表示无Issue编号,则从提交信息中移除整个行。
Issue:Step 4: User Confirmation
步骤4:用户确认
Present the complete commit message draft in this format:
=== Commit Message Draft ===
<full draft content>
=== End Draft ===
Confirm? (Yes/No/Modify)- If user confirms with "Yes" → proceed to commit
- If user says "No" → ask for feedback and regenerate
- If user wants to "Modify" → incorporate their changes and present again for confirmation
Important: You must get explicit user approval before committing. Never auto-commit.
将完整的提交信息草稿按以下格式展示:
=== 提交信息草稿 ===
<完整草稿内容>
=== 草稿结束 ===
是否确认?(是/否/修改)- 若用户回复“是” → 执行提交
- 若用户回复“否” → 询问反馈并重新生成
- 若用户选择“修改” → 结合用户的修改内容,再次展示草稿供确认
重要提示:必须获得用户的明确同意后再执行提交,禁止自动提交。
Step 5: Execute Commit
步骤5:执行提交
After user confirms, execute:
bash
git commit -m "<commit message>"Return success message to user.
用户确认后,执行以下命令:
bash
git commit -m "<commit message>"向用户返回提交成功的提示。
Handling Special Cases
特殊场景处理
Initial Commit
初始提交
If repository has no commits yet (detached HEAD or shows no HEAD), the first commit will be:
git statusbash
git commit -m "<commit message>"This works without parent commits automatically.
若仓库尚无任何提交(处于分离HEAD状态或显示无HEAD),第一次提交直接执行:
git statusbash
git commit -m "<commit message>"该命令会自动处理无父提交的情况。
Empty Diff
空差异
If returns no output, inform user that there are no staged changes and they need to stage files first.
git diff --staged若返回空内容,告知用户当前无已暂存的变更,需要先暂存文件。
git diff --stagedExamples
示例
Example 1: Feature with PMS and Issue
示例1:关联PMS和Issue的功能提交
User request: "帮我提交这个功能的代码"
- Check status → User stages and
src/auth.rssrc/auth_test.rs - Diff shows authentication logic addition
- Provide draft:
feat(auth): add JWT authentication support
Add JWT-based authentication middleware with token validation.
添加JWT认证中间件,支持令牌验证。
Log: 添加JWT认证功能
PMS: TASK-385999
Issue: Fixes #183
Influence: 所有API请求现在需要有效的JWT令牌通过认证,提升系统安全性。- User confirms "可以提交"
- Execute
git commit
用户请求:“帮我提交这个功能的代码”
- 检查状态 → 用户暂存和
src/auth.rssrc/auth_test.rs - 差异内容显示新增了认证逻辑
- 生成草稿:
feat(auth): add JWT authentication support
Add JWT-based authentication middleware with token validation.
添加JWT认证中间件,支持令牌验证。
Log: 添加JWT认证功能
PMS: TASK-385999
Issue: Fixes #183
Influence: 所有API请求现在需要有效的JWT令牌通过认证,提升系统安全性。- 用户确认“可以提交”
- 执行
git commit
Example 2: Bug fix without PMS
示例2:无PMS的Bug修复提交
User request: "commit this bug fix"
- User stages fix, no PMS or Issue
- Provide draft:
fix(user): resolve incorrect user role assignment
Use correct role mapping from database configuration.
修复用户角色分配错误的bug,使用正确的数据库配置映射。
Log: 修复角色映射bug
Influence: 修复后用户角色分配逻辑正确,避免权限错误。- User confirms and commit
用户请求:“commit this bug fix”
- 用户暂存修复内容,无PMS或Issue
- 生成草稿:
fix(user): resolve incorrect user role assignment
Use correct role mapping from database configuration.
修复用户角色分配错误的bug,使用正确的数据库配置映射。
Log: 修复角色映射bug
Influence: 修复后用户角色分配逻辑正确,避免权限错误。- 用户确认后执行提交
Tips
小贴士
- Always explain what you're about to do before executing git commands
- If user provides feedback on the draft, show the complete revised message again for confirmation
- The Log field should be the most concise Chinese summary
- Influence should clearly state the impact on the system/users
- When in doubt, ask user for clarification rather than guessing
- 在执行Git命令前,务必向用户说明即将进行的操作
- 若用户对草稿提出反馈,展示完整的修订版草稿供再次确认
- Log字段应为最简洁的中文总结
- Influence字段应清晰说明变更对系统/用户的影响
- 如有疑问,向用户确认而非自行猜测