根据用户提供的代码变更内容(git diff 输出或口头描述),智能分析改动范围和类型,生成符合 Conventional Commits 规范的提交消息候选方案。
当用户请求生成 Git 提交消息时激活,常见触发语句包括:
提交消息格式:
text
<type>(<scope>): <short description>
[optional body]
[optional footer(s)]
类型说明示例feat新功能feat(auth): add OAuth2 login support``fix修复 bugfix(api): handle null pointer in user endpoint``docs文档变更docs(readme): update installation instructions``style代码格式(不影响功能)style(lint): fix indentation in utils.ts``refactor重构(非新功能、非修复)refactor(database): simplify query builder``perf性能优化perf(render): reduce re-renders in list component``test测试相关test(auth): add unit tests for login flow``chore构建过程或辅助工具变动chore(deps): update react to v18.2.0``ciCI/CD 配置变更ci(github): add automated testing workflow
如果改动包含 BREAKING CHANGE,需在类型后添加 ! 或在正文/脚注中明确标注:
text
feat(api)!: change authentication endpoint response format
BREAKING CHANGE: The /api/auth/login endpoint now returns a different JSON structure.
询问用户提供以下任一形式的输入:
git diff 或 git diff --staged 的完整输出如果用户未提供具体内容,主动询问:
"请提供 git diff 输出,或描述本次代码改动的内容(例如:添加了用户登录功能、修复了空指针异常等)。"
基于用户输入,执行以下分析:
auth, ui, api, database, config 等core)根据改动内容确定 type:
featfixdocsstylerefactorperftestchoreci检查是否存在以下情况:
如果存在,标记为 BREAKING CHANGE。
生成 3 条 不同详细程度的推荐提交消息:
格式: <type>(<scope>): <short description>
格式:
text
<type>(<scope>): <short description>
<detailed body explaining what and why>
格式:
text
<type>(<scope>): <short description>
<detailed body>
BREAKING CHANGE: <description of breaking change>
Closes #123
以清晰的结构化格式输出:
markdown
## 📝 推荐的提交消息
### 选项 1:简洁版
```
text
<commit message with body>
text
<commit message with body and footer>
text
### 步骤 5:交互优化
提供后续操作建议:
- "需要我将某条消息复制到剪贴板吗?"
- "是否需要调整某个选项的描述?"
- "是否要生成英文版本的提交消息?"
## 示例对话
### 示例 1:用户提供 git diff
**用户**:
commit message for this change
diff --git a/src/auth/login.ts b/src/auth/login.ts index abc123..def456 100644 --- a/src/auth/login.ts +++ b/src/auth/login.ts @@ -10,6 +10,15 @@ export class AuthService {
text
**助手**:
```markdown
## 📝 推荐的提交消息
### 选项 1:简洁版
feat(auth): add OAuth2 login support
text
### 选项 2:标准版
feat(auth): add OAuth2 login support
Implement OAuth2 authentication flow to allow users to login with third-party providers like Google and GitHub.
text
### 选项 3:完整版
feat(auth): add OAuth2 login support
Implement OAuth2 authentication flow to allow users to login with third-party providers like Google and GitHub.
Closes #42
text
## 🔍 分析说明
- **改动类型**:feat - 新增了 OAuth2 登录功能
- **影响范围**:auth - 改动集中在认证模块
- **破坏性变更**:否 - 仅新增方法,未修改现有接口
用户:
text
帮我写一个 commit,我修复了一个 bug,当用户输入为空时,搜索功能会崩溃
助手:
markdown
## 📝 推荐的提交消息
### 选项 1:简洁版
fix(search): handle empty input to prevent crash
text
### 选项 2:标准版
fix(search): handle empty input to prevent crash
Add input validation to search function to gracefully handle empty or null queries instead of throwing an exception.
text
### 选项 3:完整版
fix(search): handle empty input to prevent crash
Add input validation to search function to gracefully handle empty or null queries instead of throwing an exception.
Fixes #156
text
## 🔍 分析说明
- **改动类型**:fix - 修复了导致崩溃的 bug
- **影响范围**:search - 问题出现在搜索功能
- **破坏性变更**:否 - 仅增强健壮性,未改变接口行为
(scope) 部分解决方案:
core, app, multiple解决方案:
chore 作为保守选择解决方案:
如果环境支持,可实现以下增强:
git commit -m "<message>"