关于 commit-message
commit-message 是用于分析 Git 变更并起草上下文相关 Conventional Commits 消息的命令行技能。它帮助开发者查看变更文件、按关联内容拆分提交,并描述代码改动的实际目的。
主要功能
- 01列出变更文件、状态和类别
- 02建议多次提交的文件分组
- 03按指定文件模式生成消息
- 04仅分析已暂存的变更
- 05遵循 Conventional Commits 类型与范围
适用场景
- 01提交前检查仓库中的全部变更
- 02将无关工作拆分为多次提交
- 03为选定文件起草提交消息
- 04将代码改动整理为目的明确的描述
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ jiatastic/ open-python-skills --skill commit-message安装后在 Claude Code 中输入/commit-message确认已加载。
附带文件data/commit_patterns.jsonscripts/analyze_changes.py
详细介绍
commit-message
分析 Git 更改,并按照 Conventional Commits 生成结合上下文的提交消息。
快速开始
# Analyze all changes
python3 .shared/commit-message/scripts/analyze_changes.py --analyze
# Get batch commit suggestions
python3 .shared/commit-message/scripts/analyze_changes.py --batch
# Generate message for specific files
python3 .shared/commit-message/scripts/analyze_changes.py --generate "src/api/*.py"
命令
| 命令 | 描述 |
|---|---|
--analyze | 显示所有已更改文件的状态和类别 |
--batch | 建议如何将更改拆分为多个提交 |
--generate [pattern] | 为匹配的文件生成提交消息 |
--staged | 仅分析暂存的更改(默认:所有更改) |
提交类型
| 类型 | 描述 | 示例 |
|---|---|---|
feat | 新功能 | feat(api): add user authentication |
fix | 修复错误 | fix(db): resolve connection timeout |
refactor | 重构代码 | refactor(utils): simplify helper functions |
docs | 文档 | docs: update README |
test | 测试 | test(api): add user endpoint tests |
chore | 维护 | chore: update dependencies |
style | 格式调整 | style: fix linting errors |
批量提交工作流
当有多个不相关的更改时:
- 运行
--batch查看建议的提交分组 - 暂存第一个提交的文件:
git add <files> - 使用建议的消息进行提交
- 对剩余分组重复上述步骤
分组策略
文件按以下方式分组:
- 目录/模块:
src/api/、tests/、docs/ - 更改类型:新增、修改或删除
- 语义关系:将相关文件放在一起
结合上下文的提交消息
注意:
analyze_changes.py脚本会对文件进行分组并提供基本建议。将其输出作为起点,然后阅读git diff,了解实际更改,并参考以下示例生成结合上下文的消息。
生成提交消息时,分析实际代码更改以推断业务背景。不要只描述文件,而要说明这些更改实现了什么。
作用域指南
作用域应体现业务模块或功能,而不只是目录:
| 作用域类型 | 示例 | 使用场景 |
|---|---|---|
| 功能/模块 | companion、calendar、inbox | 更改特定产品功能时 |
| 平台 | ios、android、web | 平台特定的更改 |
| 集成 | outlook、gmail、slack | 第三方集成相关的更改 |
| 组件 | auth、api、db | 核心基础设施相关的更改 |
输入/输出示例
示例 1:新功能
Input (code changes):
+ src/companion/pages/AvailabilityDetailPage.tsx
+ src/companion/pages/AvailabilityActionsPage.tsx
+ src/companion/components/AvailabilityCard.tsx
M src/companion/navigation/routes.ts
Output:
feat(companion): add availability detail and actions pages for ios
- New AvailabilityDetailPage showing time slot details
- New AvailabilityActionsPage for booking/canceling
- AvailabilityCard component for list display
- Updated navigation routes
示例 2:修复错误
Input (code changes):
M src/integrations/outlook/email_sender.py
M src/integrations/outlook/auth.py
Output:
fix(outlook): resolve email sending failures due to token expiration
Refresh OAuth token before sending when close to expiry
示例 3:多平台更改
Input (code changes):
M ios/Calendar/CalendarView.swift
M android/calendar/CalendarFragment.kt
M web/src/calendar/Calendar.tsx
Output:
feat(calendar): add week view across all platforms
Implement consistent week view UI for iOS, Android, and web
示例 4:杂项/维护
Input (code changes):
M package.json
M yarn.lock
M requirements.txt
Output:
chore(deps): update dependencies to latest versions
撰写优质描述
| 不佳(泛泛而谈) | 良好(结合上下文) |
|---|---|
feat: add new file | feat(payments): add Stripe webhook handler |
fix: fix bug | fix(auth): prevent session timeout on mobile |
chore: update code | chore(ci): reduce build time with parallel jobs |
refactor: refactor utils | refactor(api): extract rate limiting to middleware |
核心原则
- 阅读代码——了解更改实际实现的内容
- 确定功能——受到影响的是哪项面向用户的功能或系统能力?
- 具体明确——包含相关细节(平台、集成、组件)
- 使用主动语态——使用“add”“fix”“update”,而非“added”“fixed”“updated”
- 保持简洁——首行少于 72 个字符
评论
支持 Markdown