$npx -y skills add flamingoTOM/Auto-CV --skill git-commit-helper根据 git diff 生成符合规范的 commit message。当用户需要提交代码、生成中文 commit message 或查看代码变更时使用。
| 1 | # Git Commit Helper |
| 2 | |
| 3 | |
| 4 | |
| 5 | ## 认证 |
| 6 | Github 平台的 api key: `<GITHUB_TOKEN>` |
| 7 | |
| 8 | ## Instructions |
| 9 | |
| 10 | ### 步骤 1: 检查当前状态 |
| 11 | 运行 `git status` 查看当前仓库状态,了解有哪些文件被修改。 |
| 12 | |
| 13 | ### 步骤 2: 查看变更内容 |
| 14 | 运行 `git diff --staged` 查看已暂存的更改(如果有的话)。 |
| 15 | 如果没有暂存的更改,运行 `git diff` 查看工作区的更改。 |
| 16 | |
| 17 | ### 步骤 3: 分析变更类型 |
| 18 | 根据变更内容,确定 commit 类型: |
| 19 | - **feat**: 新功能(feature) |
| 20 | - **fix**: 修复 bug |
| 21 | - **docs**: 仅文档更改 |
| 22 | - **style**: 不影响代码含义的更改(空格、格式化等) |
| 23 | - **refactor**: 既不修复 bug 也不添加功能的代码重构 |
| 24 | - **perf**: 提升性能的代码更改 |
| 25 | - **test**: 添加或修改测试 |
| 26 | - **chore**: 构建过程或辅助工具的变动 |
| 27 | |
| 28 | ### 步骤 4: 生成 Commit Message |
| 29 | 使用中文按照 Conventional Commits 规范生成消息: |
| 30 | |
| 31 | **格式:** |
| 32 | ``` |
| 33 | <type>(<scope>): <subject> |
| 34 | |
| 35 | <body> |
| 36 | |
| 37 | <footer> |
| 38 | ``` |
| 39 | |
| 40 | **规则:** |
| 41 | - subject: 简短描述,不超过 50 字符,使用祈使句 |
| 42 | - body: 详细描述,说明为什么做这个更改(可选) |
| 43 | - footer: 关联的 issue 或 breaking changes(可选) |
| 44 | |
| 45 | ## Examples |
| 46 | |
| 47 | ### 示例 1: 新增功能 |
| 48 | **变更:** 添加了用户登录功能,包含 JWT token 验证 |
| 49 | |
| 50 | **生成的 Commit Message:** |
| 51 | ``` |
| 52 | feat(auth): add JWT-based user authentication |
| 53 | |
| 54 | - Implement login endpoint at /api/auth/login |
| 55 | - Add JWT token generation and verification |
| 56 | - Create authentication middleware for protected routes |
| 57 | - Add user session management |
| 58 | |
| 59 | Related: #123 |
| 60 | ``` |
| 61 | |
| 62 | ### 示例 2: 修复 Bug |
| 63 | **变更:** 修复了日期格式在时区转换时的错误 |
| 64 | |
| 65 | **生成的 Commit Message:** |
| 66 | ``` |
| 67 | fix(utils): correct date formatting in timezone conversion |
| 68 | |
| 69 | The previous implementation didn't handle daylight saving time |
| 70 | correctly. Now using moment-timezone library for consistent |
| 71 | UTC timestamp conversion. |
| 72 | |
| 73 | Fixes: #456 |
| 74 | ``` |
| 75 | |
| 76 | ### 示例 3: 文档更新 |
| 77 | **变更:** 更新了 README 中的安装说明 |
| 78 | |
| 79 | **生成的 Commit Message:** |
| 80 | ``` |
| 81 | docs(readme): update installation instructions |
| 82 | |
| 83 | Add detailed steps for Docker-based setup and |
| 84 | troubleshooting section for common installation issues. |
| 85 | ``` |
| 86 | |
| 87 | ### 示例 4: 代码重构 |
| 88 | **变更:** 重构了数据库查询逻辑,提取公共方法 |
| 89 | |
| 90 | **生成的 Commit Message:** |
| 91 | ``` |
| 92 | refactor(db): extract common query patterns into helper functions |
| 93 | |
| 94 | Move repeated query logic into reusable helper functions |
| 95 | to improve code maintainability and reduce duplication. |
| 96 | |
| 97 | No functional changes. |
| 98 | ``` |
| 99 | |
| 100 | ## Best Practices |
| 101 | |
| 102 | 1. **简短而精确**: subject 应该简明扼要,一眼就能看出做了什么 |
| 103 | 2. **使用祈使句**: 使用 "add" 而不是 "added" 或 "adds" |
| 104 | 3. **解释原因**: 在 body 中说明为什么做这个更改,而不是重复 subject |
| 105 | 4. **一个 commit 一个目的**: 如果有多个不相关的更改,建议拆分成多个 commits |
| 106 | 5. **关联 issue**: 如果有相关的 issue,在 footer 中引用 |
| 107 | |
| 108 | ## Quick Reference |
| 109 | |
| 110 | | Type | 使用场景 | |
| 111 | |------|---------| |
| 112 | | feat | 添加新功能 | |
| 113 | | fix | 修复 bug | |
| 114 | | docs | 仅文档更改 | |
| 115 | | style | 代码格式调整(不影响逻辑)| |
| 116 | | refactor | 代码重构(不修复 bug,不添加功能)| |
| 117 | | perf | 性能优化 | |
| 118 | | test | 添加或修改测试 | |
| 119 | | chore | 构建工具或依赖更新 | |