| Crates.io | git-commit-helper-cli |
| lib.rs | git-commit-helper-cli |
| version | 0.9.2 |
| created_at | 2026-01-21 08:52:31.368506+00 |
| updated_at | 2026-01-21 09:24:22.621984+00 |
| description | A CLI tool to help generate standardized git commit messages |
| homepage | |
| repository | |
| max_upload_size | |
| id | 2058678 |
| size | 328,640 |
一个强大的 Git 提交消息助手,支持多个 AI 服务,实现智能提交消息生成和中英互译
🤖 多 AI 服务支持
注意:目前仅 Claude 服务尚未经过完整测试。如果您在使用此服务时遇到问题,欢迎反馈。
🔧 高度可定制
📝 智能提交
🔍 智能代码审查
🌏 中英双语
📋 测试建议
📝 产品日志
# 克隆仓库
git clone https://github.com/zccrs/git-commit-helper
cd git-commit-helper
# 快速安装(推荐)
./install.sh
# Arch Linux
yay -S git-commit-helper
# Debian/Ubuntu
sudo apt install git-commit-helper
# Fedora
sudo dnf install git-commit-helper
添加软件源:
# 添加GPG公钥(暂未实现)
# curl -fsSL https://zccrs.github.io/git-commit-helper/KEY.gpg | sudo gpg --dearmor -o /usr/share/keyrings/git-commit-helper.gpg
# 添加软件源
echo "deb [trusted=yes] https://zccrs.github.io/git-commit-helper/ stable main" | sudo tee /etc/apt/sources.list.d/git-commit-helper.list
# 更新软件源并安装
sudo apt update
sudo apt install git-commit-helper
git-commit-helper config
git-commit-helper install
# 智能生成提交信息
git add .
git-commit-helper commit
# 或者手动编写并自动翻译
git commit
为所有慢速网络请求(如 GitHub PR、Gerrit、AI 服务等)增加了进度提示,进度信息会持续在同一行动态刷新,避免用户误以为程序卡死。示例输出:
正在请求 github.com 获取PR内容 ...
正在请求 github.com 获取PR内容 100%...
正在请求 api.openai.com 进行代码审查 30%...
进度条会根据请求阶段自动更新,所有输出均直接使用 print/println,确保用户一定能看到。
以下是一个实际的提交消息翻译示例:
原始提交消息:
支持将原中文内容自动换行处理
如原中文内容是:"我是中文commit信息",在翻译处理后,
可能会变成:
"我是中文\ncommit信息",这取决于一行的长度
否超出git的推荐值。
翻译后的提交消息:
Support automatic line breaking for the original Chinese content
If the original Chinese content is: "我是中文commit信息", after
translation,
it may become:
"我是中文\ncommit信息", depending on whether the length of
a line exceeds the recommended value of git.
支持将原中文内容自动换行处理
如原中文内容是:"我是中文commit信息",在翻译处理后,
可能会变成:
"我是中文\ncommit信息",这取决于一行的长度
否超出git的推荐值。
使用翻译命令有三种方式:
# 方式1:指定文件路径
git-commit-helper translate -f path/to/file
# 方式2:指定文本内容
git-commit-helper translate -t "要翻译的文本"
# 方式3:智能判断(推荐)
git-commit-helper translate "要翻译的文本" # 文本内容
git-commit-helper translate /path/to/existing/file # 文件路径
命令会自动判断参数内容:如果是一个存在的文件路径则读取文件内容进行翻译,否则将参数内容作为文本进行翻译。
| 命令 | 说明 | 示例 |
|---|---|---|
| config | 配置 AI 服务 | git-commit-helper config [--set-only-chinese <true|false>/--set-only-english <true|false>] |
| show | 显示当前配置 | git-commit-helper show |
| install | 安装 Git Hook | git-commit-helper install [-f] |
| ai add | 添加 AI 服务 | git-commit-helper ai add |
| ai edit | 编辑 AI 服务配置 | git-commit-helper ai edit |
| ai remove | 删除 AI 服务 | git-commit-helper ai remove |
| ai set-default | 设置默认服务 | git-commit-helper ai set-default |
| ai set-timeout | 设置请求超时 | git-commit-helper ai set-timeout -s 30 |
| ai list | 列出所有服务 | git-commit-helper ai list |
| ai test | 测试指定服务 | git-commit-helper ai test [-t "测试文本"] |
| translate | 翻译内容 | git-commit-helper translate [-f 文件] [-t 文本] |
| commit | 生成提交信息 | git-commit-helper commit [-t 类型] [-m 描述] [-a] [--amend] [--no-review/--no-influence/--no-log/--only-chinese/--only-english] [--issues ISSUE...] |
| ai-review | 管理 AI 代码审查 | git-commit-helper ai-review [--enable/--disable/--status] |
| 类型 | 说明 | 使用场景 |
|---|---|---|
| feat | 新功能 | 添加新特性 |
| fix | 修复问题 | 修复 bug |
| docs | 文档更新 | 更新文档 |
| style | 格式调整 | 不影响代码逻辑的格式修改 |
| refactor | 代码重构 | 不修复问题也不添加特性的代码更改 |
| test | 测试相关 | 添加或修改测试用例 |
| chore | 其他更新 | 构建过程或辅助工具的变更 |
# 配置
git-commit-helper config [选项]
--set-only-chinese <true|false> 设置默认是否只使用中文提交信息
# 远程代码审查
git-commit-helper <URL>
支持以下代码平台的改动审查:
1. GitHub
- PR: https://github.com/owner/repo/pull/123
- Commit: https://github.com/owner/repo/commit/hash
2. Gerrit
- Change: https://gerrit.uniontech.com/c/udcp/udcp-uim/+/179042
# AI 代码审查管理
git-commit-helper ai-review [选项]
--enable 全局启用代码审查功能
--disable 全局禁用代码审查功能
--status 查看代码审查功能的当前状态
# 生成提交信息
git-commit-helper commit [选项]
-t, --type <TYPE> 指定提交类型 (可选)
-m, --message <MSG> 提供对改动的描述 (可选)
-a, --all 自动添加所有已修改但未暂存的文件
--no-review 禁用当前提交的代码审查功能
--no-influence 禁用当前提交的影响分析(测试建议)功能
--no-log 禁用当前提交的产品日志字段
--only-chinese 仅保留中文提交信息
--only-english 仅保留英文提交信息
--issues [ISSUE...] 关联多个GitHub issue或PMS链接
示例:
# 生成提交信息
git-commit-helper commit
# 指定提交类型
git-commit-helper commit --type feat
# 提供改动描述
git-commit-helper commit --message "修复了用户无法登录的问题"
# 自动添加所有修改并提交
git-commit-helper commit -a
# 完整示例
git-commit-helper commit --type fix --message "修复内存泄漏" -a
# 设置默认使用中文
git-commit-helper config --set-only-chinese true # 默认仅使用中文
# 设置默认使用英文
git-commit-helper config --set-only-english true # 默认仅使用英文
# 设置默认使用中英双语
git-commit-helper config --set-only-chinese false --set-only-english false # 默认使用中英双语
# 单次提交使用中文
git-commit-helper commit --type feat --message "添加新功能" --only-chinese
# 单次提交使用英文
git-commit-helper commit --type feat --message "Add new functions" --only-english
# 禁用影响分析(测试建议)
git-commit-helper commit --no-influence
# 禁用产品日志字段
git-commit-helper commit --no-log
# 同时禁用代码审查、影响分析和产品日志
git-commit-helper commit --no-review --no-influence --no-log
# 关联GitHub issue
git-commit-helper commit --issues "https://github.com/owner/repo/issues/123"
git-commit-helper commit --issues "123" # 当前项目的issue
git-commit-helper commit --issues "123" "456" "789" # 多个issue
# 关联PMS链接
git-commit-helper commit --issues "https://pms.uniontech.com/bug-view-320461.html"
git-commit-helper commit --issues "https://pms.uniontech.com/task-view-374223.html"
git-commit-helper commit --issues "https://pms.uniontech.com/story-view-38949.html"
# 混合关联
git-commit-helper commit --issues "123" "https://pms.uniontech.com/bug-view-320461.html"
git-commit-helper commit --issues "https://github.com/owner/repo/issues/123" "https://pms.uniontech.com/task-view-374223.html"
# 修补上次提交
git-commit-helper commit --amend
git-commit-helper commit --amend --only-chinese
工具提供两种代码审查方式:
工具在生成提交信息时会自动包含测试建议部分,帮助开发者明确测试重点:
智能测试建议生成
测试范围覆盖
灵活控制
--no-test-suggestions 参数禁用示例生成的测试建议:
feat: 添加用户认证模块
1. 实现基于 JWT 的认证系统
2. 添加用户登录和注册端点
3. 包含使用 bcrypt 的密码哈希处理
4. 设置令牌刷新机制
Log: 新增用户登录注册功能
Influence:
1. 测试用户注册功能,包括有效和无效输入
2. 验证登录功能,测试正确和错误的凭据
3. 测试 JWT 令牌生成和验证流程
4. 验证密码安全性和哈希处理
5. 测试令牌刷新机制和过期处理
6. 验证受保护端点的访问控制
工具支持在提交信息中自动关联 GitHub issue 和 PMS 链接,使提交与相关任务建立明确的关联关系:
GitHub Issue 关联
PMS 链接关联
多链接支持
引用字段格式
Fixes: #123 或 Fixes: owner/repo#123Fixes: #123 #456 owner/repo#789PMS: BUG-320461PMS: TASK-374223PMS: STORY-38949PMS: BUG-123 TASK-456 STORY-789使用示例:
# 单个 GitHub issue (当前项目)
git-commit-helper commit --issues "123"
# 生成: Fixes: #123
# 多个 GitHub issue (当前项目)
git-commit-helper commit --issues "123 456 789"
# 生成: Fixes: #123 #456 #789
# 混合不同项目的 GitHub issue
git-commit-helper commit --issues "123 https://github.com/owner/repo/issues/456"
# 生成: Fixes: #123 owner/repo#456
# 多个 PMS 链接
git-commit-helper commit --issues "https://pms.uniontech.com/bug-view-320461.html https://pms.uniontech.com/task-view-374223.html"
# 生成: PMS: BUG-320461 TASK-374223
# 混合 GitHub 和 PMS
git-commit-helper commit --issues "123 https://pms.uniontech.com/bug-view-320461.html"
# 生成:
# Fixes: #123
# PMS: BUG-320461
# 使用逗号分隔
git-commit-helper commit --issues "123,456,789"
# 生成: Fixes: #123 #456 #789
# 混合分隔符
git-commit-helper commit --issues "123 456,https://pms.uniontech.com/task-view-374223.html"
# 生成:
# Fixes: #123 #456
# PMS: TASK-374223
工具支持自动生成产品导向的日志字段,帮助产品经理向用户清晰传达功能变化:
智能识别用户功能
面向用户的表达
应用场景
Log: 新增深色模式主题Log: 优化搜索界面交互体验Log: 修复无法保存文件的问题Log: 支持设置鼠标光标大小不生成Log的情况
使用示例:
# 添加用户功能时会生成Log字段
git-commit-helper commit
# 可能生成:
# feat: add dark mode theme support
#
# 1. Implement theme switching mechanism
# 2. Add dark mode color scheme
# 3. Update all UI components for theme support
#
# Log: 新增深色模式主题
#
# Influence:
# 1. Test theme switching in different scenarios
# 2. Verify color contrast meets accessibility standards
# 技术重构时不会生成Log字段
git-commit-helper commit
# 可能生成:
# refactor: optimize database query performance
#
# 1. Replace N+1 queries with batch loading
# 2. Add database connection pooling
# 3. Optimize slow query indexes
#
# Influence:
# 1. Test query performance under load
# 2. Verify data consistency after optimization
远程代码审查功能包含:
提交信息翻译
代码变更审查
远程审查支持的平台:
示例:
# 审查 GitHub PR
git-commit-helper https://github.com/owner/repo/pull/123
# 审查 GitHub commit
git-commit-helper https://github.com/owner/repo/commit/hash
# 审查 Gerrit change
git-commit-helper https://gerrit.example.com/c/project/+/123456
输出格式:
标题:<原始标题>
中文翻译:<标题翻译>
描述:
<原始描述>
中文翻译:
<描述翻译>
代码审查报告:
...(详细的代码审查内容)
你可以通过以下方式控制代码审查功能:
# 启用代码审查
git-commit-helper ai-review --enable
# 禁用代码审查
git-commit-helper ai-review --disable
# 查看当前状态
git-commit-helper ai-review --status
# 提交时临时禁用代码审查
git-commit-helper commit --no-review
# 或者在编辑提交信息时禁用
git commit --no-review
更新版本时需要修改以下文件:
Cargo.toml
[package]
version = "x.y.z" # 更新版本号
debian/changelog 和 git-commit-helper.spec
注意:debian 和 rpm 包的 changelog 都需要更新,并且内容要保持一致。
对于 debian/changelog:
git-commit-helper (x.y.z) unstable; urgency=medium
* 此处列出从上一版本到当前版本的所有提交记录,可以通过以下命令获取:
git log <上一版本>..HEAD --oneline
按类型整理提交记录,例如:
* feat: 添加的新功能
* fix: 修复的问题
* docs: 文档更新
* chore: 其他修改
-- 作者 <邮箱> `date "+%a, %d %b %Y %H:%M:%S %z"` # 使用系统当前时间
对于 git-commit-helper.spec:
%changelog
* 发布日期 作者 <邮箱> - x.y.z-1
# 此处列出与 debian/changelog 相同的更新内容,保持格式一致:
- feat: 添加的新功能
- fix: 修复的问题
- docs: 文档更新
- chore: 其他修改
PKGBUILD
pkgver=x.y.z # 更新版本号
git-commit-helper.spec
Version: x.y.z # 更新版本号
# 在 %changelog 部分添加新版本信息
* 发布日期 作者 <邮箱> - x.y.z-1
- Release version x.y.z
- 更新内容描述...
Git 标签
# 提交更改
git add .
git commit -m "chore: bump version to x.y.z"
# 创建新标签
git tag -a vx.y.z -m "Release version x.y.z"
# 推送更改和标签
git push origin master
git push origin vx.y.z
src/
├── ai_service.rs # AI 服务实现
├── auth/ # 认证相关模块
├── commit.rs # 提交消息处理
├── config.rs # 配置管理
├── debug.rs # 调试工具
├── gerrit.rs # Gerrit 集成
├── github.rs # GitHub 集成
├── git.rs # Git 操作
├── install.rs # 安装工具
├── lib.rs # 库入口
├── main.rs # 主程序
└── review.rs # 代码审查
# 打包脚本使用方法
./install.sh package [arch|deb|rpm]
# 手动打包
makepkg -sf # Arch Linux
dpkg-buildpackage # Debian
rpmbuild -ba *.spec # RPM
本项目支持通过 GitHub Actions 自动将 PKGBUILD 及相关文件推送到 AUR 仓库,实现一键同步更新。
在 GitHub 仓库设置 Secrets:
添加名为 AUR_SSH_PRIVATE_KEY 的 secret,内容为你的 AUR 账户 SSH 私钥(建议使用专用密钥,且设置只读权限)。
可选:如需自定义 AUR 仓库地址,添加 AUR_REPO_URL secret。
获取方法:
git clone ssh://aur@aur.archlinux.org/your-aur-repo.git
ssh://aur@aur.archlinux.org/your-aur-repo.git 作为 AUR_REPO_URL 的值。GitHub Actions Workflow 示例:
jobs:
aur-publish:
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.AUR_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts
- name: Clone AUR repo
run: |
git clone "${{ secrets.AUR_REPO_URL || 'ssh://aur@aur.archlinux.org/<your-aur-repo>.git' }}" aur-repo
- name: Update PKGBUILD and files
run: |
cp PKGBUILD aur-repo/
# 如有其它 AUR 文件一并复制
cd aur-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add PKGBUILD
git commit -m "chore: update PKGBUILD to ${{ github.ref_name }}"
git push origin master
注意事项:
常见问题:
cp 和 git add 命令。默认配置路径:
~/.config/git-commit-helper/config.json~/Library/Application Support/git-commit-helper/config.json%APPDATA%\git-commit-helper\config.json通过设置环境变量 RUST_LOG 可以开启调试日志:
# 开启全部调试日志
export RUST_LOG=debug
git-commit-helper ...
# 或者在运行时临时开启
RUST_LOG=debug git-commit-helper ...
# 仅开启特定模块的调试日志
RUST_LOG=git_commit_helper=debug git-commit-helper ...
常用日志级别:
欢迎提交 Issue 和 Pull Request!
本项目采用 MIT 许可证。