casperdcl/git-fame
GitHub: casperdcl/git-fame
git-fame 是一个 Git 仓库贡献统计工具,按多种维度排序并精美打印协作者的代码贡献数据。
Stars: 820 | Forks: 39
# git-fame
精美打印按贡献量排序的 ``git`` 仓库协作者。
|Py-Versions| |PyPI| |Conda-Forge| |Docker| |Snapcraft|
|Build-Status| |Coverage-Status| |Branch-Coverage-Status| |Codacy-Grade| |Libraries-Rank| |PyPI-Downloads|
.. code::
```
https://git-fame.cdcl.ml/gh/{owner}/{repo}
```
|Contributions|
.. code:: sh
```
git fame --cost hour,month --loc ins
```
.. code:: sh
```
Processing: 100%|██████████████████████████| 1/1 [00:00<00:00, 2.16repo/s]
Total commits: 1775
Total ctimes: 2770
Total files: 461
Total hours: 449.7
Total loc: 41659
Total months: 151.0
| Author | hrs | mths | loc | coms | fils | distribution |
|:---------------------|------:|-------:|------:|-------:|-------:|:----------------|
| Casper da Costa-Luis | 228 | 108 | 28572 | 1314 | 172 | 68.6/74.0/37.3 |
| Stephen Larroque | 28 | 18 | 5243 | 203 | 25 | 12.6/11.4/ 5.4 |
| pgajdos | 2 | 9 | 2606 | 2 | 18 | 6.3/ 0.1/ 3.9 |
| Martin Zugnoni | 2 | 5 | 1656 | 3 | 3 | 4.0/ 0.2/ 0.7 |
| Kyle Altendorf | 7 | 2 | 541 | 31 | 7 | 1.3/ 1.7/ 1.5 |
| Hadrien Mary | 5 | 1 | 469 | 31 | 17 | 1.1/ 1.7/ 3.7 |
| Richard Sheridan | 2 | 1 | 437 | 23 | 3 | 1.0/ 1.3/ 0.7 |
| Guangshuo Chen | 3 | 1 | 321 | 18 | 7 | 0.8/ 1.0/ 1.5 |
| Noam Yorav-Raphael | 4 | 1 | 229 | 11 | 6 | 0.5/ 0.6/ 1.3 |
| github-actions[bot] | 2 | 1 | 186 | 1 | 51 | 0.4/ 0.1/11.1 |
...
```
``distribution``(分布)列是 ``loc/coms/fils`` 的百分比细分。
(例如,在上表中,Casper 在所有文件中 ``172/461 = 37.3%`` 的文件里编写了尚存代码)。
.. contents:: Table of contents
:backlinks: top
:local:
## 安装说明
### 最新的 PyPI 稳定版
|PyPI| |PyPI-Downloads| |Libraries-Dependents|
.. code:: sh
```
pip install git-fame
```
### GitHub 上最新的开发版本
|GitHub-Status| |GitHub-Stars| |GitHub-Commits| |GitHub-Forks| |GitHub-Updated|
拉取并安装:
.. code:: sh
```
pip install "git+https://github.com/casperdcl/git-fame.git@main#egg=git-fame"
```
### 最新的 Conda 版本
|Conda-Forge|
.. code:: sh
```
conda install -c conda-forge git-fame
```
### 最新的 Snapcraft 版本
|Snapcraft|
.. code:: sh
```
snap install git-fame
```
### 最新的 Docker 版本
|Docker|
.. code:: sh
```
docker run --rm casperdcl/git-fame --help
docker run --rm -v "/local/path/to/repository:/repo" -u "$(id -u)" casperdcl/git-fame
```
### 注册为 git 别名
在 Windows 上,运行:
.. code:: sh
```
git config --global alias.fame "!python -m gitfame"
```
在 UNIX 系统上可能不需要这样做。
如果在 Linux 和 Mac OS 上重启终端后 ``git fame`` 仍然不起作用,请尝试(使用单引号):
.. code:: sh
```
git config --global alias.fame '!python -m gitfame'
```
### Tab 补全
(可选)安装了 ``bash-completion`` 的系统可以安装 Tab 补全支持。
需要将 `git-fame_completion.bash `_
文件复制到合适的文件夹中。
在 Ubuntu 上,操作步骤如下:
.. code:: sh
```
$ # Ensure completion works for `git` itself
$ sudo apt-get install bash-completion
$ # Install `git fame` completions
$ sudo wget \
https://raw.githubusercontent.com/casperdcl/git-fame/main/git-fame_completion.bash \
-O /etc/bash_completion.d/git-fame_completion.bash
```
然后重启终端。
## 更新日志
所有更改的列表可在 Releases 页面上查看:|GitHub-Status|
## 使用说明
.. code:: sh
```
git fame # If alias registered with git (see above)
git-fame # Alternative execution as python console script
python -m gitfame # Alternative execution as python module
git-fame -h # Print help
```
例如,要打印有关 C++/CUDA 仓库(``*.c/h/t(pp), *.cu(h)``)中所有源文件的统计数据,并谨慎处理空格和代码行复制:
.. code:: sh
```
git fame --incl '\.[cht][puh]{0,2}$' -twMC
```
也可以在 Python shell 或脚本中运行。
.. code:: python
```
>>> import gitfame
>>> gitfame.main(['--sort=commits', '-wt', '/path/to/my/repo'])
```
最后,有一个针对公开 GitHub 仓库的实时服务器,地址为 `git-fame.cdcl.ml/gh/{owner}/{repo} `_。
## 文档
.. code::
```
Usage:
git-fame [--help | options] [...]
Arguments:
Git directory [default: ./].
May be specified multiple times to aggregate across
multiple repositories.
Options:
-h, --help Print this help and exit.
-v, --version Print module version and exit.
--branch= Branch or tag [default: HEAD] up to which to check.
--sort= [default: loc]|commits|files|hours|months.
--min= Minimum value (of `--sort` key) to show [default: 0:int].
--loc= surv(iving)|ins(ertions)|del(etions)
What `loc` represents. Use 'ins,del' to count both.
defaults to 'surviving' unless `--cost` is specified.
--excl= Excluded files (default: None).
In no-regex mode, may be a comma-separated list.
Escape (\,) for a literal comma (may require \\, in shell).
--incl= Included files [default: .*]. See `--excl` for format.
--since= Date from which to check. Can be absolute (eg: 1970-01-31)
or relative to now (eg: 3.weeks).
--until= Date to which to check. See `--since` for format.
--cost= Include time cost in person-months (COCOMO) or
person-hours (based on commit times).
Methods: month(s)|cocomo|hour(s)|commit(s).
May be multiple comma-separated values.
Alters `--loc` default to imply 'ins' (COCOMO) or
'ins,del' (hours).
-R, --recurse Recursively find repositories & submodules within .
-n, --no-regex Assume are comma-separated exact matches
rather than regular expressions [default: False].
NB: if regex is enabled ',' is equivalent to '|'.
-s, --silent-progress Suppress `tqdm` [default: False].
--warn-binary Don't silently skip files which appear to be binary data
[default: False].
--show= Author information to show [default: name]|email.
Use 'name,email' to show both.
-e, --show-email Shortcut for `--show=email`.
--enum Show row numbers [default: False].
-t, --bytype Show stats per file extension [default: False].
-w, --ignore-whitespace Ignore whitespace when comparing the parent's
version and the child's to find where the lines
came from [default: False].
-M Detect intra-file line moves and copies [default: False].
-C Detect inter-file line moves and copies [default: False].
--ignore-rev= Ignore changes made by the given revision
(requires `--loc=surviving`).
--ignore-revs-file= Ignore revisions listed in the given file
(requires `--loc=surviving`).
--format= Table format
svg|[default: pipe]|md|markdown|yaml|yml|json|csv|tsv|tabulate.
May require `git-fame[]`, e.g. `pip install git-fame[yaml]`.
Any `tabulate.tabulate_formats` is also accepted.
--manpath= Directory in which to install git-fame man pages.
--log= FATAL|CRITICAL|ERROR|WARN(ING)|[default: INFO]|DEBUG|NOTSET.
```
如果多个用户名和/或电子邮件对应同一个用户,可以通过添加
`.mailmap 文件 `_ 来聚合 ``git-fame`` 统计数据并妥善维护 ``git`` 仓库。
### 常见问题
诸如 ``-w``、``-M`` 和 ``-C`` 等选项可以提高准确性,但计算时间会更长。
请注意,指定 ``--sort=hours`` 或 ``--sort=months`` 需要正确指定 ``--cost``。
请注意,``--cost=months``(``--cost=COCOMO``)近似于
`人月 `_,应与 ``--loc=ins`` 配合使用。
同时,``--cost=hours``(``--cost=commits``)近似于
`人时 `_。
当为 ``--loc`` 使用 ``ins`` 和/或 ``del`` 时应格外小心,因为所有历史文件(包括那些不再保留的文件)都会被计算在内。
在这种情况下,可能需要大幅扩展 ``--excl`` 的范围。
好的一面是,与 ``surv`` 相比,计算 ``ins`` 和 ``del`` 会更快。
## 示例
### 徽章
用于包含在 README 文件和网站中的 SVG 图像:
.. code:: sh
git fame -wMC --format svg --min 1 > docs/authors.svg
也可以为公开的 GitHub 仓库动态生成:
.. code:: md

### CODEOWNERS
生成
`CODEOWNERS `_:
.. code:: sh
```
# 用于当前目录 git repository 的 bash syntax function
owners(){
for f in $(git ls-files); do
# filename
echo -n "$f "
# author emails if loc distribution >= 30%
git fame -esnwMC --incl "$f" | tr '/' '|' \
| awk -F '|' '(NR>6 && $6>=30) {print $2}' \
| xargs echo
done
}
# 打印到屏幕和文件
owners | tee .github/CODEOWNERS
# 相同,但对于大型 repos 带有 `tqdm` 进度
owners \
| tqdm --total $(git ls-files | wc -l) \
--unit file --desc "Generating CODEOWNERS" \
> .github/CODEOWNERS
```
### Zenodo 配置
生成 `.zenodo.json `_:
.. code:: sh
```
git fame -wMC --format json \
| jq -c '{creators: [.data[] | {name: .[0]}]}' \
| sed -r -e 's/(\{"name")/\n \1/g' -e 's/:/: /g' \
> .zenodo.json
```
## 许可证
开源(OSI 批准):|LICENCE|
引用信息:|DOI-URI|
|README-Hits|
.. |Build-Status| image:: https://img.shields.io/github/actions/workflow/status/casperdcl/git-fame/test.yml?branch=main&label=git-fame&logo=GitHub
:target: https://github.com/casperdcl/git-fame/actions/workflows/test.yml
.. |Coverage-Status| image:: https://img.shields.io/coveralls/github/casperdcl/git-fame/main?logo=coveralls
:target: https://coveralls.io/github/casperdcl/git-fame
.. |Branch-Coverage-Status| image:: https://codecov.io/gh/casperdcl/git-fame/branch/main/graph/badge.svg
:target: https://codecov.io/gh/casperdcl/git-fame
.. |Codacy-Grade| image:: https://api.codacy.com/project/badge/Grade/bde789ee0e57491eb2bb8609bd4190c3
:target: https://www.codacy.com/app/casper-dcl/git-fame/dashboard
.. |GitHub-Status| image:: https://img.shields.io/github/tag/casperdcl/git-fame.svg?maxAge=86400&logo=github
:target: https://github.com/casperdcl/git-fame/releases
.. |GitHub-Forks| image:: https://img.shields.io/github/forks/casperdcl/git-fame.svg?logo=github
:target: https://github.com/casperdcl/git-fame/network
.. |GitHub-Stars| image:: https://img.shields.io/github/stars/casperdcl/git-fame.svg?logo=github
:target: https://github.com/casperdcl/git-fame/stargazers
.. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/casperdcl/git-fame?label=commits&logo=git
:target: https://github.com/casperdcl/git-fame/graphs/commit-activity
.. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/casperdcl/git-fame.svg?logo=github
:target: https://github.com/casperdcl/git-fame/issues
.. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/casperdcl/git-fame.svg?logo=github
:target: https://github.com/casperdcl/git-fame/pulls
.. |Contributions| image:: https://git-fame.cdcl.ml/gh/casperdcl/git-fame
:target: https://git-fame.cdcl.ml/gh/casperdcl/git-fame
.. |GitHub-Updated| image:: https://img.shields.io/github/last-commit/casperdcl/git-fame?label=pushed&logo=github
:target: https://github.com/casperdcl/git-fame/pulse
.. |Sponsor-Casper| image:: https://img.shields.io/badge/sponsor-FOSS-dc10ff.svg?logo=Contactless%20Payment
:target: https://cdcl.ml/sponsor
.. |PyPI| image:: https://img.shields.io/pypi/v/git-fame.svg?logo=PyPI&logoColor=white
:target: https://pypi.org/project/git-fame
.. |PyPI-Downloads| image:: https://static.pepy.tech/personalized-badge/git-fame?left_text=downloads%2Fmonth
:target: https://pepy.tech/project/git-fame
.. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/git-fame.svg?logo=python&logoColor=white
:target: https://pypi.org/project/git-fame
.. |Conda-Forge| image:: https://img.shields.io/conda/v/conda-forge/git-fame.svg?label=conda-forge&logo=conda-forge
:target: https://anaconda.org/conda-forge/git-fame
.. |Snapcraft| image:: https://img.shields.io/badge/snap-install-blue.svg?logo=snapcraft&logoColor=white
:target: https://snapcraft.io/git-fame
.. |Docker| image:: https://img.shields.io/badge/docker-pull-blue.svg?logo=docker&logoColor=white
:target: https://hub.docker.com/r/casperdcl/git-fame
.. |Libraries-Rank| image:: https://img.shields.io/librariesio/sourcerank/pypi/git-fame.svg?color=green&logo=koding
:target: https://libraries.io/pypi/git-fame
.. |Libraries-Dependents| image:: https://img.shields.io/librariesio/dependent-repos/pypi/git-fame.svg?logo=koding
:target: https://github.com/casperdcl/git-fame/network/dependents
.. |OpenHub-Status| image:: https://www.openhub.net/p/git-fame/widgets/project_thin_badge?format=gif
:target: https://www.openhub.net/p/git-fame?ref=Thin+badge
.. |LICENCE| image:: https://img.shields.io/pypi/l/git-fame.svg?color=purple&logo=SPDX
:target: https://raw.githubusercontent.com/casperdcl/git-fame/main/LICENCE
.. |DOI-URI| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.2544975-blue.svg?color=purple&logo=ORCID
:target: https://doi.org/10.5281/zenodo.2544975
.. |README-Hits| image:: https://cgi.cdcl.ml/hits?q=git-fame&style=social&r=https://github.com/casperdcl/git-fame
:target: https://cgi.cdcl.ml/hits?q=git-fame&a=plot&r=https://github.com/casperdcl/git-fame&style=social
标签:Git, SOC Prime, 代码示例, 代码统计, 域名侦查, 开发工具, 数据分析, 网络安全研究, 请求拦截, 逆向工具