ado-commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseADO Commit
ADO 提交
Create a conventional commit on an Azure DevOps-hosted repository: $ARGUMENTS
在Azure DevOps托管的仓库中创建约定式提交:$ARGUMENTS
Current state
当前状态
- Git status: !
git status --porcelain - Current branch: !
git branch --show-current - Staged diff (stat): !
git diff --cached --stat - Unstaged diff (stat): !
git diff --stat - Recent commits: !
git log --oneline -5
- Git状态:!
git status --porcelain - 当前分支:!
git branch --show-current - 暂存差异(统计):!
git diff --cached --stat - 未暂存差异(统计):!
git diff --stat - 最近提交:!
git log --oneline -5
Workflow
工作流程
The only ADO-specific bits are (a) work-item trailers and (b) the conventions this repo has adopted for talking to reviewers who open PRs in Azure DevOps.
- Stage. If nothing is staged, stage all modified and new files with . If specific files are already staged, commit only those.
git add -A - Diff. Run to understand the actual change. Read the diff — don't just trust the path names — because the message needs to describe what changed and why, not which files changed.
git diff --cached - Split if needed. If the staged diff contains multiple unrelated logical changes, propose splitting into separate commits. One commit = one reason to change.
- Write the message in Conventional Commits format (see below), then commit via . Pass trailers with
git commit --message "<subject>" [--trailer ...]so git formats them correctly; don't cat-heredoc them into the body.--trailer - Don't skip pre-commit hooks. If exists, hooks run automatically and their failures are signal, not noise. Never pass
.pre-commit-config.yaml.--no-verify
ADO专属的内容仅包括两点:(a) 工作项尾部信息;(b) 此仓库针对Azure DevOps中PR评审者采用的约定规范。
- 暂存:如果没有文件被暂存,使用暂存所有修改和新增文件。如果已有特定文件被暂存,则仅提交这些文件。
git add -A - 查看差异:运行了解实际变更内容。仔细阅读差异内容——不要只依赖文件名——因为提交信息需要描述变更内容及原因,而非哪些文件被变更。
git diff --cached - 按需拆分:如果暂存的差异包含多个不相关的逻辑变更,建议拆分为多个独立提交。一个提交对应一个变更理由。
- 编写提交信息:采用约定式提交(Conventional Commits)格式(见下文),然后通过执行提交。使用
git commit --message "<subject>" [--trailer ...]参数传递尾部信息,确保Git正确格式化;不要通过 heredoc 将其写入提交正文。--trailer - 不要跳过预提交钩子:如果存在文件,钩子会自动运行,其失败是有效信号而非干扰。切勿使用
.pre-commit-config.yaml参数跳过。--no-verify
Conventional Commits — quick reference
约定式提交——快速参考
<type>(optional scope): <description>
<optional body>
<optional trailers>Common types: , , , , , , , , , , . Append after type/scope for breaking changes (e.g. ). Keep the subject under 72 characters, imperative mood, no trailing period.
featfixdocsstylerefactorperftestbuildcichorerevert!feat(api)!: change response formatExamples:
feat(auth): add JWT refresh endpoint
fix(ui): resolve layout shift on mobile nav
refactor(db): migrate from raw SQL to query builder
chore(deps): bump TypeScript to 5.5
feat(api)!: change pagination response shape<类型>(可选作用域): <描述>
<可选正文>
<可选尾部信息>常见类型:(新功能)、(缺陷修复)、(文档更新)、(格式调整,不影响代码逻辑)、(代码重构)、(性能优化)、(测试相关)、(构建流程变更)、(持续集成配置变更)、(杂项任务,如依赖更新)、(回滚提交)。在类型/作用域后添加表示破坏性变更(例如)。主题部分控制在72字符以内,使用祈使语气,末尾不加句号。
featfixdocsstylerefactorperftestbuildcichorerevert!feat(api)!: change response format示例:
feat(auth): add JWT refresh endpoint
fix(ui): resolve layout shift on mobile nav
refactor(db): migrate from raw SQL to query builder
chore(deps): bump TypeScript to 5.5
feat(api)!: change pagination response shapeWork-item trailers (ADO-specific)
工作项尾部信息(ADO专属)
Azure DevOps auto-links commits to work items when the message contains . Include one whenever you can identify the target work item, because it keeps the board in sync without anyone clicking around.
AB#<id>Where to find the ID:
- Branch name — patterns like ,
feature/1234-...,bug/AB1234-...usually encode the work item ID.user/name/1234-... - User input — if the user mentions "work item 1234" or "this closes 1234", use that.
- Prior commits on the branch — run and check if earlier commits reference an ID.
git log --oneline origin/main..HEAD - ADO MCP — if the project has the MCP server configured and you're still unsure, call
azure-devops(orwit_my_work_itemswith a keyword from the change) to surface likely candidates. Ask the user to confirm rather than guessing.search_workitem
How to add it — as a trailer, not in the subject:
bash
git commit \
--message "feat(auth): add JWT refresh endpoint" \
--trailer "AB#1234" \
--trailer "Assistant-model: Claude Code"If you genuinely can't find a work-item ID, skip the trailer rather than inventing one. A missing trailer is recoverable; a wrong one pollutes the board.
Azure DevOps会在提交信息包含时自动将提交与工作项关联。只要能确定目标工作项ID,就应添加该信息,这样无需手动操作即可保持看板同步。
AB#<id>查找ID的途径:
- 分支名称——类似、
feature/1234-...、bug/AB1234-...的分支命名模式通常包含工作项ID。user/name/1234-... - 用户输入——如果用户提及“工作项1234”或“此提交关闭1234”,则使用该ID。
- 分支上的历史提交——运行,检查早期提交是否引用了某个ID。
git log --oneline origin/main..HEAD - ADO MCP——如果项目配置了MCP服务器且仍不确定ID,可调用
azure-devops(或使用变更中的关键字调用wit_my_work_items)来查找可能的候选工作项。若无法确定,请询问用户确认,不要猜测。search_workitem
添加方式——作为尾部信息,而非主题部分:
bash
git commit \
--message "feat(auth): add JWT refresh endpoint" \
--trailer "AB#1234" \
--trailer "Assistant-model: Claude Code"如果确实无法找到工作项ID,请跳过尾部信息,不要编造。缺失的尾部信息可后续补充,但错误的信息会污染看板数据。
AI authorship trailer
AI创作尾部信息
ADO code reviews often surface in audit contexts, so mark AI-assisted commits honestly. Use an trailer rather than — most git tooling validates the latter as an email, and we want to distinguish assistance from authorship:
Assistant-modelCo-authored-byAssistant-model: Claude CodeAdd it every time you commit on the user's behalf.
ADO代码评审常涉及审计场景,因此需如实标注AI辅助的提交。使用尾部信息而非——大多数Git工具会验证后者是否为邮箱格式,且我们希望区分辅助创作与实际作者:
Assistant-modelCo-authored-byAssistant-model: Claude Code每次代表用户执行提交时都需添加此信息。
Putting it together
整合示例
bash
git add -A
git diff --cached --stat # sanity check
git commit \
--message "fix(parser): handle nested escape sequences" \
--trailer "AB#5678" \
--trailer "Assistant-model: Claude Code"
git log -1 # show the user the resultbash
git add -A
git diff --cached --stat # 合理性检查
git commit \
--message "fix(parser): handle nested escape sequences" \
--trailer "AB#5678" \
--trailer "Assistant-model: Claude Code"
git log -1 # 向用户展示结果