ai-git-msg
v1.0.1
Published
AI-powered conventional commit message generator. Read diff → Generate → Confirm → Commit.
Maintainers
Readme
ai-commit
AI 驱动的 Git Commit Message 生成器 —— 读 diff → 生成 → 确认 → 提交,一条命令搞定。
English | 中文
特性
- 零依赖 — 无 required dependencies,
npx秒级执行 - 多 AI 模型 — OpenAI / DeepSeek / Claude / 通义千问 / Gemini / Ollama,自动识别
- Conventional Commits — 支持 Angular / Conventional / Simple / Gitmoji 四种规范
- 交互确认 — 生成后确认 / 编辑 / 重新生成 / 取消,完全可控
- 中英文 — commit message 和 CLI 均支持中英文
- 配置化 —
.ai-commit.json团队共享规范 - 兼容 — 环境变量兼容
ai-review-pipeline,无需重复配置
快速开始
# 1. 配置 API Key(任选一种模型服务,写入 .env.local)
# OpenAI
echo 'OPENAI_API_KEY=sk-xxx' >> .env.local
# DeepSeek(国内推荐,便宜好用)
echo 'DEEPSEEK_API_KEY=sk-xxx' >> .env.local
# 本地 Ollama(无需 Key)
echo 'AI_REVIEW_PROVIDER=ollama' >> .env.local
# 2. Stage 你的改动
git add .
# 3. AI 生成 commit message
npx ai-git-msg安装
# 方式一:项目级安装(推荐团队使用)
npm install -D ai-git-msg
# 方式二:全局安装
npm install -g ai-git-msg
# 方式三:不安装,npx 直接用
npx ai-git-msg安装后可使用短名 aic 替代 ai-commit。
使用流程
$ npx ai-commit
📝 正在分析 staged 变更...
📂 变更统计: src/auth/login.ts | 32 +++++++++
🤖 正在调用 AI 生成 commit message...
🔗 Provider: deepseek
🧠 模型: deepseek-chat
┌─────────────────────────────────────────────┐
│ 🤖 Generated commit message: │
└─────────────────────────────────────────────┘
feat(auth): 添加 Google OAuth 登录支持
- 新增 GoogleOAuthButton 组件处理重定向
- 实现 OAuth 回调路由完成 token 交换
- 更新 auth store 持久化 OAuth token
Confirm? [Y]es / [n]o / [e]dit / [r]egenerate > y
🎉 ✅ 已提交: feat(auth): 添加 Google OAuth 登录支持命令参数
| 参数 | 说明 |
|------|------|
| --style <type> | 规范风格:angular(默认) / conventional / simple / gitmoji |
| --lang <zh\|en> | commit message 语言(默认中文) |
| --one-line | 只生成标题行(不含 body) |
| --dry-run | 只展示,不执行提交 |
| --scope <name> | 手动指定 scope |
| -y / --yes | 跳过确认,直接提交 |
| --help / -h | 显示帮助 |
| --version / -v | 显示版本 |
子命令
| 命令 | 说明 |
|------|------|
| ai-commit | 默认:生成 commit message |
| ai-commit init | 初始化 .ai-commit.json 配置文件 |
规范风格
Angular(默认)
feat(auth): 添加 Google OAuth 登录支持
- 新增 GoogleOAuthButton 组件
- 实现 OAuth 回调路由Conventional
feat: 添加 Google OAuth 登录支持Simple
添加 Google OAuth 登录支持Gitmoji
✨ feat(auth): 添加 Google OAuth 登录支持支持的 AI 模型
| Provider | 默认模型 | 环境变量 |
|----------|---------|---------|
| OpenAI | gpt-4o-mini | OPENAI_API_KEY |
| DeepSeek | deepseek-chat | DEEPSEEK_API_KEY |
| Claude | claude-sonnet-4-20250514 | ANTHROPIC_API_KEY |
| 通义千问 | qwen-plus | DASHSCOPE_API_KEY |
| Gemini | gemini-2.0-flash | GEMINI_API_KEY |
| Ollama | qwen2.5-coder | 无需 Key |
| 自定义 | — | AI_COMMIT_API_KEY + AI_COMMIT_BASE_URL |
也可使用 AI_REVIEW_* 系列环境变量(与 ai-review-pipeline 兼容)。
配置文件
运行 ai-commit init 生成 .ai-commit.json:
{
"style": "angular", // angular | conventional | simple | gitmoji
"language": "zh", // zh | en
"maxDiffLines": 500, // diff 超过此行数截断
"scopeMap": {}, // 路径 → scope 映射(v1.1)
"types": [ // 允许的 commit type
"feat", "fix", "refactor", "docs", "style", "test", "chore", "perf", "ci"
],
"emoji": false, // 是否默认启用 gitmoji
"autoConfirm": false, // 是否跳过确认
"model": "" // 指定模型
}环境变量
| 变量 | 说明 |
|------|------|
| OPENAI_API_KEY | OpenAI API Key |
| DEEPSEEK_API_KEY | DeepSeek API Key |
| ANTHROPIC_API_KEY | Anthropic Claude API Key |
| DASHSCOPE_API_KEY | 阿里通义千问 API Key |
| GEMINI_API_KEY | Google Gemini API Key |
| AI_COMMIT_API_KEY | 通用 Key(优先级最高) |
| AI_COMMIT_PROVIDER | 手动指定 Provider |
| AI_COMMIT_BASE_URL | 自定义 API 地址 |
| AI_COMMIT_MODEL | 覆盖默认模型 |
| HTTPS_PROXY | HTTP 代理 |
兼容 AI_REVIEW_* 系列变量。支持 .env.local 和 .env 文件自动加载。
常用命令速查
npx ai-commit # 默认:分析 staged,生成 commit message
npx ai-commit --style gitmoji # gitmoji 风格
npx ai-commit --style simple # 简单一行描述
npx ai-commit --lang en # 英文 commit message
npx ai-commit --dry-run # 只展示不提交
npx ai-commit -y # 跳过确认直接提交
npx ai-commit --scope auth # 手动指定 scope
npx ai-commit init # 生成配置文件工具链
代码编写
│
├── ai-review-pipeline ── Review → Test → Report
│
├── ai-commit ── Diff → AI Message → Confirm → Commit
│
└── ai-changelog (coming) ── Git Log → CHANGELOGEnglish
What is this?
An AI-powered Git commit message generator. Reads staged diff → AI generates Conventional Commit message → You confirm → Done. Supports OpenAI, DeepSeek, Claude, Qwen, Gemini, Ollama and any OpenAI-compatible API.
Quick Start
echo 'DEEPSEEK_API_KEY=sk-xxx' >> .env.local
git add .
npx ai-git-msgOptions
| Option | Description |
|--------|-------------|
| --style <type> | Style: angular(default) / conventional / simple / gitmoji |
| --lang <zh\|en> | Message language (default: zh) |
| --one-line | Subject line only |
| --dry-run | Preview only, don't commit |
| --scope <name> | Manually specify scope |
| -y / --yes | Skip confirmation |
Install
npm install -D ai-git-msg # Project-level
npm install -g ai-git-msg # Global
npx ai-git-msg # No install neededUse --lang en for English commit messages.
License
MIT
