Commit and Push
Commit all local changes following Conventional Commits format and push to remote.
Step 1: Gather Context
Run these commands in parallel to understand the changes:
CODEBLOCK0
Step 2: Analyze Changes
Review the changes and determine:
- - Type: What kind of change is this?
-
feat - New feature or capability
-
fix - Bug fix
-
docs - Documentation only
-
refactor - Code restructure without behavior change
-
test - Adding or updating tests
-
chore - Maintenance, dependency updates
-
perf - Performance improvement
-
ci - CI/CD changes
- - Scope: Which component is affected?
- Examine the changed files and determine the appropriate scope
- Use consistent scope names within the project (check
git log for patterns)
-
(omit scope for cross-cutting changes)
- - Breaking: Does this break backward compatibility? If yes, add ! after scope.
Step 3: Write Commit Message
Format:
CODEBLOCK1
Rules:
- - Use imperative mood: "add feature" not "added feature"
- Keep first line under 72 characters
- Focus on why in the body, the diff shows what
- Reference issues:
Closes #123 or INLINECODE10
Step 4: Stage, Commit, and Push
CODEBLOCK2
Examples
CODEBLOCK3
Step 5: Verify
After pushing, run git status to confirm the working tree is clean and the branch is up to date with remote.
提交与推送
遵循约定式提交格式提交所有本地更改并推送到远程仓库。
第1步:收集上下文
并行运行以下命令以了解更改:
bash
查看所有未跟踪和已修改的文件
git status
查看已暂存和未暂存的更改
git diff
git diff --cached
查看最近的提交信息以参考风格
git log --oneline -10
第2步:分析更改
审查更改并确定:
- feat - 新功能或能力
- fix - 错误修复
- docs - 仅文档
- refactor - 代码重构,不改变行为
- test - 添加或更新测试
- chore - 维护、依赖更新
- perf - 性能改进
- ci - CI/CD更改
- 检查更改的文件并确定适当的范围
- 在项目中使用一致的范围名称(查看 git log 了解模式)
-
(跨领域更改可省略范围)
- - 破坏性:是否破坏向后兼容性?如果是,在范围后添加 !。
第3步:编写提交信息
格式:
type(scope): description
[可选正文,解释原因而非内容]
[可选页脚,引用问题编号]
规则:
- - 使用祈使语气:add feature 而非 added feature
- 第一行保持在72个字符以内
- 正文关注原因,差异显示内容
- 引用问题:Closes #123 或 Fixes #456
第4步:暂存、提交和推送
bash
暂存所有更改(或选择性暂存)
git add -A
提交信息(使用HEREDOC支持多行)
git commit -m $(cat <
可选正文,解释动机。
Closes #123
使用 Claude Code 生成
Co-Authored-By: Claude
EOF
)
推送到远程
git push
示例
bash
简单功能
git commit -m feat(api): add pagination support to list endpoints
带正文的错误修复
git commit -m $(cat <之前的实现没有考虑在长时间运行的请求处理过程中
令牌过期的情况。
Fixes #42
使用 Claude Code 生成
Co-Authored-By: Claude
EOF
)
破坏性更改
git commit -m $(cat <BREAKING CHANGE: status 字段现在是一个包含 state 和
message 属性的对象,而非纯字符串。
使用 Claude Code 生成
Co-Authored-By: Claude
EOF
)
第5步:验证
推送后,运行 git status 确认工作区干净且分支与远程仓库保持同步。