AI Commit Message Generator
一键生成 Git commit message 并填充到 Windsurf/VSCode 的输入框。
✨ 功能特性
- 🚀 一键生成 commit message
- 🤖 支持多种 AI 服务提供商:OpenAI、Gemini、Anthropic、智谱 AI
- 📝 支持多种 message 格式:Conventional Commits、简单、详细、自定义
- 🌍 支持中英文输出
- 📦 支持多 Git 仓库项目,智能检测当前仓库
- ⌨️ 快捷键支持
📦 安装
# 1. 进入项目目录
cd smart-commit-msg
# 2. 安装依赖
pnpm install
# 3. 编译
pnpm run compile
# 4. 打包成 .vsix 文件
pnpm run package
# 5. 在 Windsurf/VSCode 中安装
# - 打开命令面板 (Cmd+Shift+P)
# - 输入 "Extensions: Install from VSIX"
# - 选择生成的 ai-commit-message-x.x.x.vsix 文件
🚀 使用方法
方法一:点击按钮
在 Source Control 面板的标题栏点击 ✨ 按钮
方法二:快捷键
按 Cmd+Shift+M (Mac) 或 Ctrl+Shift+M (Windows/Linux)
方法三:命令面板
- 打开命令面板
Cmd+Shift+P
- 输入 "AI: 生成提交信息"
⚙️ 配置说明
在 VSCode/Windsurf 设置中搜索 aiCommit 进行配置。
基础配置
| 配置项 |
说明 |
默认值 |
aiCommit.provider |
AI 服务提供商 |
openai |
aiCommit.language |
输出语言 (zh/en) |
zh |
aiCommit.messageFormat |
消息格式 |
conventional |
aiCommit.maxDiffLength |
最大 diff 长度 |
8000 |
aiCommit.customPrompt |
自定义 Prompt(当格式为 custom 时使用) |
- |
AI 提供商配置
OpenAI(及兼容接口)
| 配置项 |
说明 |
默认值 |
aiCommit.openai.baseUrl |
API Base URL |
https://api.openai.com/v1 |
aiCommit.openai.apiKey |
API Key |
- |
aiCommit.openai.model |
模型名称 |
gpt-4o-mini |
支持所有 OpenAI 兼容接口:
- Ollama:
http://localhost:11434/v1
- Azure OpenAI:
https://your-resource.openai.azure.com/openai/deployments/your-deployment
- DeepSeek:
https://api.deepseek.com/v1
- Moonshot:
https://api.moonshot.cn/v1
Google Gemini
| 配置项 |
说明 |
默认值 |
aiCommit.gemini.baseUrl |
API Base URL |
https://generativelanguage.googleapis.com/v1beta |
aiCommit.gemini.apiKey |
API Key |
- |
aiCommit.gemini.model |
模型名称 |
gemini-1.5-flash |
Anthropic Claude
| 配置项 |
说明 |
默认值 |
aiCommit.anthropic.baseUrl |
API Base URL |
https://api.anthropic.com |
aiCommit.anthropic.apiKey |
API Key |
- |
aiCommit.anthropic.model |
模型名称 |
claude-3-5-sonnet-20241022 |
智谱 AI (GLM)
| 配置项 |
说明 |
默认值 |
aiCommit.zhipu.baseUrl |
API Base URL |
https://open.bigmodel.cn/api/paas/v4 |
aiCommit.zhipu.apiKey |
API Key |
- |
aiCommit.zhipu.model |
模型名称 |
glm-4-flash |
Message 格式说明
| 格式 |
说明 |
示例 |
conventional |
Conventional Commits 格式 |
feat(auth): 添加用户登录功能 |
simple |
简单描述 |
添加用户登录功能 |
detailed |
详细说明(标题 + 正文) |
标题 + 空行 + 详细描述 |
custom |
自定义格式 |
使用 customPrompt 配置 |
自定义 Prompt
当 messageFormat 设置为 custom 时,可以使用 customPrompt 配置自定义 Prompt。
可用变量:
{diff} - 代码差异内容
{language} - 输出语言(中文/English)
示例:
请根据以下代码变更生成一个简洁的提交信息,使用 {language} 输出:
{diff}
🔧 配置示例
使用 Ollama 本地模型
{
"aiCommit.provider": "openai",
"aiCommit.openai.baseUrl": "http://localhost:11434/v1",
"aiCommit.openai.apiKey": "ollama",
"aiCommit.openai.model": "qwen2.5-coder:7b"
}
使用 OpenAI
{
"aiCommit.provider": "openai",
"aiCommit.openai.apiKey": "sk-your-api-key",
"aiCommit.openai.model": "gpt-4o-mini"
}
使用智谱 AI
{
"aiCommit.provider": "zhipu",
"aiCommit.zhipu.apiKey": "your-api-key",
"aiCommit.zhipu.model": "glm-4-flash"
}
使用 DeepSeek
{
"aiCommit.provider": "openai",
"aiCommit.openai.baseUrl": "https://api.deepseek.com/v1",
"aiCommit.openai.apiKey": "sk-your-api-key",
"aiCommit.openai.model": "deepseek-chat"
}
📁 多仓库支持
当项目中包含多个 Git 仓库时,扩展会智能选择:
- 单仓库:直接使用
- 多仓库:
- 优先检测当前编辑文件所在的仓库
- 如果有多个仓库都有变更,弹出选择框让用户选择
🛠️ 开发
# 监听文件变化并自动编译
pnpm run watch
# 调试:在 VSCode 中按 F5 启动扩展开发主机
📄 License
MIT