git-alias-1.2.30 is not a library.
Git-Alias
一个快速的 Git 别名工具,支持两种调用方式。
特性
- 双模式调用: 支持直接调用 (
gs) 和 g 前缀调用 (g s)
- 142+ 内置别名: 覆盖所有常用 git 操作
- 作者代码统计:
g stat 按作者聚合 commit 数、增删行数、文件数
- AI 提交摘要:
g msg 用 claude/opencode/anthropic 生成版本变更摘要
- 自定义别名: 通过
~/.git-alias.toml 添加自定义别名
- Shell 补全: 支持 bash、zsh、fish 补全脚本
- 高性能: Rust 编译,启动时间 < 1ms
安装
cargo install git-alias
配置
添加到 PATH
将以下内容添加到 .bashrc 或 .zshrc:
export PATH="$HOME/.local/bin:$PATH"
使用方法
基本命令
gs gba gcm gcmm "msg"
g s g ls g ba g cm "msg"
子命令
g list g list push g completions bash g init g install g stat g --help
作者代码统计
g stat 命令按作者聚合指定时间范围内的代码变更:
g stat
g stat alice
g stat alice@x.com g stat "alic*" g stat "re:^alic" g stat -i ALICE
g stat g stat --today g stat --yesterday g stat --week g stat --month g stat --year g stat --since=2024-01-01
g stat --since="2 weeks ago"
g stat main..HEAD g stat -a
g stat --no-merges
g stat --month -v
g stat -v alice
作者匹配语法(位置前缀区分):
| 模式 |
示例 |
说明 |
| 精确匹配 |
alice |
Author name 完全相等(大小写敏感) |
| 邮箱匹配 |
alice@x.com |
Author email 完全相等 |
| 通配符 |
alic* ali?e |
* 任意序列,? 单字符 |
| 正则 |
re:^alic |
re: 前缀为正则 |
选项:
| 选项 |
说明 |
--today |
今日 00:00 至今 |
--yesterday |
昨日 00:00 ~ 今日 00:00 |
--week |
过去 7 天 |
--month |
过去 30 天 |
--year |
过去 1 年 |
| (无时间参数) |
全部历史 |
--since <DATE> |
起始时间(git 原生语法) |
--until <DATE> |
截止时间(默认 HEAD) |
-a, --all-branches |
所有本地分支(不含 remote) |
-i, --ignore-case |
作者匹配大小写不敏感 |
--no-merges |
排除 merge commit |
-v, --verbose |
显示日均新增/删除/总变动行数(按作者实际提交日数) |
注意:
- 与
g msg 类似,A..B 范围为空时自动用 merge-base 找到分叉点
--since/--until 与 A..B range 互斥
--today/--yesterday/--week/--month 互斥,且不能与 --since/--until 同用
- 百分比以区间内全部 commit 为分母(即使用户按作者过滤)
added% = added / total_added,removed% = removed / total_removed,lines% = lines / total_lines
--verbose 额外显示 days(作者实际提交日数),以及 added/day / removed/day / lines/day
- 日均值按作者实际提交日数计算;合计行(total)的
days 为所有作者活跃日数之和
输出示例(默认,全部历史):
代码变更统计 (全部历史 · 当前分支) 2024-01-15 ~ 2025-08-12
┌─────────────┬─────────┬──────────┬───────┬────────┬─────────┬──────────┬───────┬────────┬───────┬────────┐
│ author │ commits │ commits% │ added │ added% │ removed │ removed% │ lines │ lines% │ files │ files% │
╞═════════════╪═════════╪══════════╪═══════╪════════╪═════════╪══════════╪═══════╪════════╪═══════╪════════╡
│ Alice Wang │ 42 │ 47.7% │ +1820 │ 58.4% │ -320 │ 39.3% │ 2140 │ 52.3% │ 87 │ 48.6% │
│ Bob Chen │ 18 │ 20.5% │ +640 │ 20.5% │ -180 │ 22.1% │ 820 │ 20.0% │ 45 │ 25.1% │
│ cnzf1 │ 16 │ 18.2% │ +540 │ 17.3% │ -95 │ 11.7% │ 635 │ 15.5% │ 28 │ 15.6% │
├═════════════╪═════════╪══════════╪═══════╪════════╪═════════╪══════════╪═══════╪════════╪═══════╪════════╣
│ total │ 88 │ 100.0% │ +3115 │ 100.0% │ -815 │ 100.0% │ 3930 │ 100.0% │ 179 │ 100.0% │
└─────────────┴─────────┴──────────┴───────┴────────┴─────────┴──────────┴───────┴────────┴───────┴────────┘
输出示例(g stat --month -v):
代码变更统计 (过去 30 天 · 当前分支) 2025-07-15 ~ 2025-08-12
┌─────────────┬─────────┬──────────┬──────┬───────┬────────┬───────────┬─────────┬──────────┬─────────────┬───────┬────────┬───────────┬───────┬────────┐
│ author │ commits │ commits% │ days │ added │ added% │ added/day │ removed │ removed% │ removed/day │ lines │ lines% │ lines/day │ files │ files% │
╞═════════════╪═════════╪══════════╪══════╪═══════╪════════╪═══════════╪═════════╪══════════╪═════════════╪═══════╪════════╪═══════════╪═══════╪════════╡
│ Alice Wang │ 42 │ 47.7% │ 5 │ +1820 │ 58.4% │ +364 │ -320 │ 39.3% │ -64 │ 2140 │ 52.3% │ 428 │ 87 │ 48.6% │
│ Bob Chen │ 18 │ 20.5% │ 3 │ +640 │ 20.5% │ +213 │ -180 │ 22.1% │ -60 │ 820 │ 20.0% │ 273 │ 45 │ 25.1% │
│ cnzf1 │ 16 │ 18.2% │ 3 │ +540 │ 17.3% │ +180 │ -95 │ 11.7% │ -32 │ 635 │ 15.5% │ 212 │ 28 │ 15.6% │
├═════════════╪═════════╪══════════╪══════╪═══════╪════════╪═══════════╪═════════╪══════════╪═════════════╪═══════╪════════╪═══════════╪═══════╪════════╣
│ total │ 88 │ 100.0% │ 11 │ +3115 │ 100.0% │ +283 │ -815 │ 100.0% │ -74 │ 3930 │ 100.0% │ 357 │ 179 │ 100.0% │
└─────────────┴─────────┴──────────┴──────┴───────┴────────┴───────────┴─────────┴──────────┴─────────────┴───────┴────────┴───────────┴───────┴────────┘
AI 提交摘要
g msg 命令调用 AI 工具自动生成版本变更摘要:
g msg release/v0.3.4..release/v0.3.5
g msg db8201ed..8a61f32a
g msg HEAD~10..HEAD
g msg -v HEAD~10..HEAD
g msg --verbose release/v0.3.4..release/v0.3.5
注意:
- 当
A..B 范围为空时,会自动使用 merge-base 找到分叉点,显示分叉后 B 的新提交
- 如果分支不存在,提示使用
origin/feature/xxx 远程分支名,或用 git branch -a 查看所有分支
输出示例:
## 版本变更摘要 (release/v0.3.4 → release/v0.3.5)
### 🐛 Bug 修复
- **打包问题**:修复 PR #66 引入的无法启动问题
### ✨ 新功能
- **分析**:客户端可开启显示,实时展示分析结果
- **广场**:新增广场界面
### 🔧 优化与重构
- **Kernel 更新**:合并最新 kernel
### 📝 其他
- 版本更新至 **0.3.5**
开启 -v 时,每条变更末尾追加作者信息:
### ✨ 新功能
- **分析** <张三>: 客户端可开启显示,实时展示分析结果
- **广场** <李四>: 新增广场界面
配置管理
配置文件位于 ~/.config/git-alias.toml(旧配置 ~/.git-alias.toml 会自动迁移)。
g config
g config get msg.provider
g config set msg.provider=openai
g config set msg.openai.api_key=sk-...
g config set msg.openai.model=gpt-4o
g config new
AI Provider 配置:
| Provider |
说明 |
tool |
使用 claude/opencode 等本地工具(默认) |
openai |
使用 OpenAI API |
anthropic |
使用 Anthropic API |
示例配置:
[msg]
provider = "openai"
[msg.openai]
model = "gpt-4o-mini"
api_key = "sk-..."
base_url = "https://api.openai.com/v1"
[msg.anthropic]
model = "claude-3-5-sonnet-20241022"
api_key = "sk-ant-..."
base_url = "https://api.anthropic.com"
别名列表
运行 g list 查看所有别名。
调用规则:
- 直接调用(如
gs, gps, gba):必须以 g 开头
g 前缀调用(如 g s, g ps, g ba):别名不能以 g 开头
- 以
g 开头的别名不支持 g 前缀调用(如 g gps 报错)
Add (添加)
| 别名 |
命令 |
g a |
git add |
ga |
git add |
g aa |
git add . |
gaa |
git add . |
Status (状态)
| 别名 |
命令 |
g s |
git status |
gs |
git status |
g ss |
git status -s |
gss |
git status -s |
g sb |
git status -s -b |
gsb |
git status -s -b |
Commit (提交)
| 别名 |
命令 |
g cm |
git commit |
gcm |
git commit |
g cma |
git commit --amend |
gcma |
git commit --amend |
g cmn |
git commit --no-edit --amend |
gcmn |
git commit --no-edit --amend |
g cmm |
git commit -m |
gcmm |
git commit -m |
g cmai [-en] |
git commit (AI auto message, -en for English) |
gcmai [-en] |
git commit (AI auto message, -en for English) |
Push (推送)
| 别名 |
命令 |
g ps |
git push |
gps |
git push |
g psf |
git push --force-with-lease |
gpsf |
git push --force-with-lease |
g psu |
git push -u origin HEAD |
gpsu |
git push -u origin HEAD |
Pull (拉取)
| 别名 |
命令 |
g p |
git pull |
gp |
git pull |
g pl |
git pull |
gpl |
git pull |
g pla |
git pull --all -t |
gpla |
git pull --all -t |
Branch (分支)
| 别名 |
命令 |
g b |
git branch |
gb |
git branch |
g ba |
git branch --all |
gba |
git branch --all |
g bra |
git branch -avv |
gbra |
git branch -avv |
g bv |
git branch -vv |
gbv |
git branch -vv |
g bc |
git branch --contains |
gbc |
git branch --contains |
g bcr |
git branch -r --contains |
gbcr |
git branch -r --contains |
g bd |
git branch -d |
gbd |
git branch -d |
gbD |
git branch --delete --force |
Checkout (检出)
| 别名 |
命令 |
g ck |
git checkout |
gck |
git checkout |
g ckb |
git checkout -b |
gckb |
git checkout -b |
Switch (切换)
| 别名 |
命令 |
g sw |
git switch |
gsw |
git switch |
g swc |
git switch --create |
gswc |
git switch --create |
g swd |
git switch --detach |
gswd |
git switch --detach |
g swf |
git switch --force |
gswf |
git switch --force |
Log (日志)
| 别名 |
命令 |
g l |
git log (自定义格式) |
gl |
git log (自定义格式) |
g lg |
git log -S |
glg |
git log -S |
g lgg |
git log -G |
glgg |
git log -G |
g ls |
git log --no-merges |
gls |
git log --no-merges |
g lss |
git log --no-merges --stat=200 |
glss |
git log --no-merges --stat=200 |
g lp |
git log --oneline --color -p |
glp |
git log --oneline --color -p |
Diff (差异)
| 别名 |
命令 |
g d |
git diff |
gd |
git diff |
g di |
git diff |
gdi |
git diff |
g dc |
git diff --cached |
gdc |
git diff --cached |
g ds |
git diff --stat=200 |
gds |
git diff --stat=200 |
g dw |
git diff --word-diff |
gdw |
git diff --word-diff |
Reset/Restore (重置/恢复)
| 别名 |
命令 |
g rs |
git reset |
grs |
git reset |
g rsh |
git reset --hard |
grsh |
git reset --hard |
g rss |
git reset --soft |
grss |
git reset --soft |
g un |
git restore |
gun |
git restore |
g uns |
git restore --staged |
guns |
git restore --staged |
Revert (回退)
| 别名 |
命令 |
g rvr |
git revert |
grvr |
git revert |
Stash (储藏)
| 别名 |
命令 |
g st |
git stash |
gst |
git stash |
g stp |
git stash pop |
gstp |
git stash pop |
g sta |
git stash apply |
gsta |
git stash apply |
g stl |
git stash list |
gstl |
git stash list |
g std |
git stash drop |
gstd |
git stash drop |
Remote (远程)
| 别名 |
命令 |
g r |
git remote |
gr |
git remote |
g rv |
git remote -v |
grv |
git remote -v |
g ra |
git remote add |
gra |
git remote add |
g rd |
git remote remove |
grd |
git remote remove |
Fetch (获取)
| 别名 |
命令 |
g f |
git fetch |
gf |
git fetch |
g fa |
git fetch --all --prune |
gfa |
git fetch --all --prune |
Merge (合并)
| 别名 |
命令 |
g m |
git merge |
gm |
git merge |
g mf |
git merge --ff-only |
gmf |
git merge --ff-only |
g mo |
git merge -Xtheirs |
gmo |
git merge -Xtheirs |
g mm |
git merge -Xours |
gmm |
git merge -Xours |
Rebase (变基)
| 别名 |
命令 |
g rb |
git rebase |
grb |
git rebase |
g rbi |
git rebase -i |
grbi |
git rebase -i |
g rbc |
git rebase --continue |
grbc |
git rebase --continue |
g rbun |
git rebase --abort |
grbun |
git rebase --abort |
g rbvi |
git rebase --edit-todo |
grbvi |
git rebase --edit-todo |
g rbsk |
git rebase --skip |
grbsk |
git rebase --skip |
Clone (克隆)
| 别名 |
命令 |
clo |
git clone |
gclo |
git clone |
clob |
git clone -b |
gclob |
git clone -b |
Tag (标签)
| 别名 |
命令 |
g t |
git tag |
gt |
git tag |
g tl |
git tag -l |
gtl |
git tag -l |
g tn |
git tag -n |
gtn |
git tag -n |
g ta |
git tag -a |
gta |
git tag -a |
Blame (追溯)
| 别名 |
命令 |
g bl |
git blame |
gbl |
git blame |
Worktree (工作树)
| 别名 |
命令 |
g w |
git worktree |
gw |
git worktree |
g wa |
git worktree add |
gwa |
git worktree add |
g wrm |
git worktree remove |
gwrm |
git worktree remove |
g wl |
git worktree list |
gwl |
git worktree list |
g wlck |
git worktree lock |
gwlck |
git worktree lock |
g wun |
git worktree unlock |
gwun |
git worktree unlock |
Clean (清理)
| 别名 |
命令 |
cln |
git clean --interactive -d |
gcln |
git clean --interactive -d |
g clnf |
git clean -d --force |
gclnf |
git clean -d --force |
g clnfx |
git clean -d --force -x |
gclnfx |
git clean -d --force -x |
配置文件
创建配置文件 ~/.git-alias.toml:
g init
配置示例
[aliases]
my = ["status", "-s", "-b"]
pushf = ["push", "--force-with-lease"]
wip = ["add", "-A"]
[settings]
main_branch = "main"
verbose = false
Shell 补全
Bash
source <(g completions bash)
添加到 .bashrc 以持久化:
source <(g completions bash)
Zsh
source <(g completions zsh)
添加到 .zshrc 以持久化:
source <(g completions zsh)
Fish
g completions fish > ~/.config/fish/completions/g.fish
性能
- 二进制大小: ~3.8MB (release 编译,含 line-tables 调试信息)
- 启动时间: < 1ms (CPU 时间)
- 内存占用: < 3MB
许可证
MIT