当前项目版本:v1.0.6 项目地址:<https://github.com/unc
git-air 命令使用手册
发布时间: 2026-08-22 (17 days ago)
GOAI

当前项目版本:v1.0.6
项目地址:https://github.com/unclesam-ly/git-air

git-air 是一个使用大模型审查 Git 代码变更的命令行工具,适合在提交前检查 Bug、安全问题、并发问题、资源泄漏和代码质量问题。

一、安装

Go 安装

bash 复制代码
go install github.com/unclesam-ly/git-air@latest
git-air version

从源码编译

bash 复制代码
git clone https://github.com/unclesam-ly/git-air.git
cd git-air
go build -o git-air .
sudo mv git-air /usr/local/bin/

二、命令总览

命令 用途
git air 审查当前 Git 变更
git air [diff 参数] 审查指定提交、分支差异或文件
git air config set 设置全局配置
git air config get 查看当前配置
git air msg 生成 Conventional Commit Message
git air hook install 安装 pre-commit Hook
git air hook uninstall 卸载 pre-commit Hook
git air version 查看版本信息
git air update 升级到最新版本
git air upgrade update 的别名

三、代码审查命令

bash 复制代码
# 审查当前暂存区
git add .
git air

# 显式审查暂存区
git air --cached
git air --staged

# 审查上一次提交
git air HEAD~1

# 审查指定提交
git air abc1234

# 审查两个分支之间的差异
git air main..feature-branch

# 审查指定文件
git air internal/service/user.go

临时覆盖模型配置

bash 复制代码
git air --provider deepseek --model deepseek-chat
git air --key "YOUR_API_KEY"
git air --prompt "重点检查并发安全、错误处理和资源释放问题"

阻断相关选项

bash 复制代码
# 严格模式:WARNING 也会阻断流程
git air --strict

# 非阻断模式:只输出报告,不因问题返回非零状态
git air --no-block

普通模式下,发现 [BLOCKER][CRITICAL][REJECT] 时会阻断流程;严格模式下,[WARNING][WARN] 也会阻断流程。

代码审查参数

参数 简写 说明
--key -k 临时指定 API Key
--model -m 临时指定模型名称
--provider -p 临时指定模型提供商
--prompt 临时指定 System Prompt
--cached 审查暂存区变更
--staged --cached 的另一种写法
--strict WARNING 也会阻断流程
--no-block 不阻断流程

四、配置命令

设置和查看配置

bash 复制代码
git air config set --provider gemini --key "YOUR_API_KEY"
git air config set --provider deepseek --key "YOUR_KEY" --model deepseek-chat
git air config get

支持的 Provider

geminiclaudegrokdeepseekqwenzhipumoonshotsiliconflowdoubaominimaxyigroqopenrouterollamaopenaicustom

常用配置示例

bash 复制代码
# Gemini
git air config set --provider gemini --key "YOUR_KEY" --model gemini-3.7-flash

# Claude
git air config set --provider claude --key "YOUR_KEY" --model anthropic/claude-3.7-sonnet

# DeepSeek
git air config set --provider deepseek --key "YOUR_KEY" --model deepseek-chat

# Qwen
git air config set --provider qwen --key "YOUR_KEY" --model qwen-plus

# OpenAI
git air config set --provider openai --key "YOUR_KEY" --model gpt-4o-mini

# OpenRouter
git air config set --provider openrouter --key "YOUR_KEY"

使用 Ollama 本地模型

bash 复制代码
ollama pull qwen2.5-coder
git air config set --provider ollama --model qwen2.5-coder
git air

自定义 OpenAI-compatible API

bash 复制代码
git air config set \
  --provider custom \
  --base-url "https://your-api.example.com/v1" \
  --key "YOUR_API_KEY" \
  --model "your-model"

自定义 Token 价格

单位为美元 / 1M tokens:

bash 复制代码
git air config set --price-input 0.75 --price-output 3.75

设置 Commit Message 语言

bash 复制代码
git air config set --commit-lang en
git air config set --commit-lang zh
git air config set --commit-lang ja
git air config set --commit-lang ko
git air config set --commit-lang auto

config set 参数

参数 简写 说明
--provider -p 模型提供商
--key -k API Key
--model -m 模型名称
--base-url -u 自定义 API 地址
--prompt 自定义基础 System Prompt
--price-input 输入 Token 价格
--price-output 输出 Token 价格
--commit-lang Commit Message 语言

五、AI Commit Message

bash 复制代码
# 根据当前变更生成提交信息
git air msg

# 指定语言
git air msg -l en
git air msg -l zh
git air msg -l ja
git air msg -l ko

# 自动暂存所有修改(等价于 git add -A)
git air msg -a

# 生成后直接执行 git commit
git air msg -c

# 自动暂存、生成并直接提交
git air msg -a -c

git air msg 支持以下别名:

bash 复制代码
git air commit-msg
git air commit

msg 参数

参数 简写 说明
--lang -l autozhenjako
--all -a 自动执行 git add -A
--commit -c 生成后直接执行 git commit
--key -k 临时指定 API Key
--model -m 临时指定模型
--provider -p 临时指定 Provider

六、Git Pre-commit Hook

bash 复制代码
# 在当前仓库安装
git air hook install

# 卸载
git air hook uninstall

安装后,每次执行 git commit 都会自动审查暂存区代码。

紧急跳过:

bash 复制代码
git commit --no-verify

七、版本和升级

bash 复制代码
# 查看版本
git air version

# 检查新版本
git air version --check
git air version -c

# 升级
git air update
git air upgrade

升级命令底层使用 go install github.com/unclesam-ly/git-air@latest,需要本机安装 Go。

八、项目规则:.airules

在项目根目录创建 .airules,为 AI Review 增加团队规范:

markdown 复制代码
# Team Coding Guidelines

1. 所有 SQL 操作必须位于 DAO 或 Repository 层;
2. 共享变量必须使用 sync.RWMutex 或 sync/atomic;
3. 打开的文件、数据库连接和 HTTP Body 必须及时关闭;
4. 不允许静默忽略错误。

九、忽略文件:.airignore

在项目根目录创建 .airignore,排除不希望提交给模型的文件:

gitignore 复制代码
docs/
*.md
testdata/
tests/mock/
*.env
secrets.yaml

项目还会自动过滤部分锁文件、生成文件和二进制文件,以减少无意义的 Token 消耗。

十、配置优先级

从低到高大致为:

  1. 默认配置;
  2. 全局配置:~/.git-air/config.yaml
  3. 项目配置:.git-air.yaml.git-air.ymlgit-air.yaml
  4. 环境变量;
  5. 命令行参数。

常用环境变量:

bash 复制代码
export GIT_AIR_API_KEY="YOUR_API_KEY"
export GIT_AIR_PROVIDER="deepseek"
export GIT_AIR_MODEL="deepseek-chat"
export GIT_AIR_BASE_URL="https://api.example.com/v1"
export GIT_AIR_COMMIT_LANG="en"

查看最终生效配置:

bash 复制代码
git air config get

十一、推荐工作流

bash 复制代码
# 修改代码后暂存
git add .

# 提交前审查
git air

# 修复问题后重新暂存
git add .

# 生成规范提交信息并提交
git air msg -c

如果希望每次提交自动审查:

bash 复制代码
git air hook install

十二、常见问题

没有配置 API Key

bash 复制代码
git air config set --provider deepseek --key "YOUR_API_KEY"

使用 Ollama 时不需要云端 API Key:

bash 复制代码
git air config set --provider ollama --model qwen2.5-coder

没有检测到代码变更

bash 复制代码
git status
git diff
git diff --cached
git add <文件名>
git air --cached

临时切换模型

bash 复制代码
git air --provider ollama --model qwen2.5-coder

该方式不会修改全局配置。

十三、许可证

项目采用 MIT License,欢迎提交 Issue、Pull Request 和改进建议。