AI 生成: 一个命令行工具,输入 Git 仓库路径后统计每个作者的提交次数并生成排名。
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
# git-author-stats
|
||||
|
||||
一个命令行工具,用于统计 Git 仓库中每个作者的提交次数并生成排名。
|
||||
|
||||
## 功能特点
|
||||
|
||||
- 输入 Git 仓库路径,统计所有作者的提交次数
|
||||
- 按提交次数降序排列,生成排名
|
||||
- 支持显示提交占比
|
||||
- 支持查看指定分支的统计
|
||||
- 无需安装额外依赖(仅使用 Python 标准库)
|
||||
|
||||
## 环境要求
|
||||
|
||||
- Python 3.6+
|
||||
- 系统中已安装 Git,并且 `git` 命令可在终端中直接调用
|
||||
|
||||
## 安装
|
||||
|
||||
无需安装,直接下载 `git_author_stats.py` 文件即可使用。
|
||||
|
||||
## 使用方法
|
||||
|
||||
```bash
|
||||
git_author_stats.py <仓库路径> [选项]
|
||||
```
|
||||
|
||||
### 参数说明
|
||||
|
||||
| 参数 | 说明 |
|
||||
| --- | --- |
|
||||
| `repo_path` | Git 仓库的路径(必填) |
|
||||
| `--branch` / `-b` | 指定分支,默认为当前分支 |
|
||||
| `--top` / `-t` | 只显示前 N 名作者 |
|
||||
| `--percent` / `-p` | 显示每位作者的提交占比 |
|
||||
|
||||
### 示例
|
||||
|
||||
```bash
|
||||
# 统计当前仓库
|
||||
git_author_stats.py .
|
||||
|
||||
# 统计指定路径的仓库
|
||||
git_author_stats.py /path/to/repo
|
||||
|
||||
# 统计指定分支并显示前 5 名
|
||||
git_author_stats.py /path/to/repo --branch main --top 5
|
||||
|
||||
# 显示提交占比
|
||||
git_author_stats.py /path/to/repo --percent
|
||||
```
|
||||
|
||||
### 输出示例
|
||||
|
||||
```
|
||||
仓库: /path/to/repo
|
||||
分支: main
|
||||
总提交数: 128
|
||||
|
||||
排名 作者 提交次数 占比
|
||||
------------------------------------------------
|
||||
1 Alice 68 53.13%
|
||||
2 Bob 42 32.81%
|
||||
3 Charlie 18 14.06%
|
||||
```
|
||||
|
||||
## 实现原理
|
||||
|
||||
工具通过调用 `git log` 命令获取提交记录,并解析每条提交的作者信息,
|
||||
然后使用字典统计每位作者的提交次数,最后按次数排序输出。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
git-author-stats/
|
||||
├── README.md
|
||||
└── git_author_stats.py
|
||||
```
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT
|
||||
Reference in New Issue
Block a user