# 🤖 AutoCommit > 自动生成符合 Conventional Commits 规范的 Git 提交消息,基于大语言模型(LLM)智能分析代码变更。 AutoCommit 利用 LLM(如 Qwen、OpenAI 等)理解你的代码改动,自动生成语义清晰、格式规范的提交信息,并支持一键提交。告别“fix bug”、“update file”这类模糊提交! --- ## ✨ 特性 - ✅ 自动分析 `git diff --staged` 内容 - ✅ 生成符合 [Conventional Commits](https://www.conventionalcommits.org/) 规范的提交消息 - ✅ 支持主流 LLM(Qwen、OpenAI、Ollama、DeepSeek 等) - ✅ 本地配置管理(`~/.autocommit/config.yaml`) - ✅ 安全预览模式(不自动提交) - ✅ 支持自定义系统提示词(system prompt) - ✅ 支持代理与自定义 API 地址 --- ## 🚀 快速开始 ### 1. 安装 ```bash pip install autocommit ``` > 要求 Python ≥ 3.8 ### 2. 配置(首次使用必做) 推荐使用交互式配置向导: ```bash autocommit config interactive ``` 或手动设置关键参数: ```bash # 设置 API 密钥和模型(以 Qwen 为例) autocommit config set --api-key "sk-your-api-key" --model "qwen3-14b" # 可选:设置自定义 API 地址(如使用 FastChat 或本地部署) autocommit config set --api-url "http://localhost:8000/v1" ``` > 配置文件默认保存在 `~/.autocommit/config.yaml` ### 3. 使用 AutoCommit ```bash # 1. 添加你要提交的文件 git add . # 2. 自动生成并提交 autocommit # 3. 或仅预览提交消息(不实际提交) autocommit test-commit ``` ✅ 成功!你的提交将类似: ``` feat(auth): implement JWT token refresh logic ``` --- ## 🛠️ 命令详解 | 命令 | 说明 | |------|------| | `autocommit` | 自动生成提交消息并执行 `git commit`(需有暂存文件) | | `autocommit test-commit` | **仅生成消息并打印**,不执行提交(安全预览) | | `autocommit check` | 检查当前配置是否有效,测试与 LLM 的连接 | | `autocommit check --test` | 发送一个固定测试提示,验证 LLM 能否正常响应 | | `autocommit config interactive` | 启动交互式配置向导 | | `autocommit config set [OPTIONS]` | 手动设置配置项(如 `--api-key`, `--model`, `--system-prompt` 等) | | `autocommit config show` | 显示当前配置(敏感信息已脱敏) | > 💡 主命令 `autocommit` **不接受任何参数**(如 `--model`、`--dry-run`)。所有配置必须提前通过 `config set` 完成。 --- ## 🔧 配置选项 支持以下配置项(可通过 `config set` 修改): | 参数 | 说明 | 示例 | |------|------|------| | `provider` | LLM 服务商 | `qwen`, `openai`, `ollama`, `deepseek` | | `model` | 模型名称 | `qwen3-14b`, `gpt-4o`, `llama3` | | `api_key` | API 密钥 | `sk-xxxxxx` | | `api_url` | 自定义 API 地址(可选) | `http://localhost:8000/v1` | | `proxy` | HTTP/HTTPS 代理(可选) | `http://127.0.0.1:7890` | | `system_prompt` | 自定义系统提示词(可选) | `"You are a helpful git commit message generator..."` | > ⚠️ 敏感信息(如 `api_key`)不会在 `config show` 中明文显示。 --- ## 🧪 测试与调试 - **测试 LLM 连通性**: ```bash autocommit check ``` - **测试提交消息生成逻辑**(使用真实或示例 diff): ```bash autocommit test-commit ``` - **查看详细日志**(调试用): ```bash # 设置环境变量开启调试 export AUTOCOMMIT_DEBUG=1 autocommit ``` --- ## 📝 注意事项 - 必须在 **Git 仓库根目录** 中运行,且 **有暂存的更改**(`git add` 过的文件)。 - 如果没有暂存内容,`autocommit` 会报错并退出。 - `test-commit` 命令在无暂存时会使用**内置示例 diff** 进行演示。 - 不同 LLM 提供商的 `model` 名称可能不同,请参考对应文档。 --- ## 🌐 支持的 LLM 提供商 | 提供商 | 配置 `provider` 值 | 备注 | |--------|-------------------|------| | 阿里通义千问(Qwen) | `qwen` | 推荐使用 DashScope API | | OpenAI | `openai` | 支持 GPT-3.5 / GPT-4 | | Ollama(本地) | `ollama` | 需运行 `ollama serve` | | DeepSeek | `deepseek` | 需 API Key | | 兼容 OpenAI 协议的服务器 | 任一 + `--api-url` | 如 FastChat、vLLM | --- ## 📄 许可证 MIT License --- ## 🙌 贡献与反馈 欢迎提交 Issue 或 PR! --- > Made with ❤️ for developers who care about clean Git history.