Git — 大图景
项目描述
git-big-picture
git-big-picture 是Git仓库的可视化工具。您可以将它想象为一个过滤器,它从Git仓库的DAG模型中移除不感兴趣的提交,从而揭示大图景:例如标签和分支的层次结构。 git-big-picture 支持便利的输出选项,并且可以过滤不同类别的提交。它使用Graphviz工具渲染令人愉悦的图像。
一个小例子
想象以下图形
0.1.1 0.1.2
| |
0.0 G---H---I---J---K---L---M maint
| /
A---B---C---D---E---F master
| \ /
0.1 N---O---P topic
以下提交有分支和标签
A -> 0.0
B -> 0.1
F -> master
H -> 0.1.1
J -> 0.1.2
M -> maint
P -> topic
有趣的提交的简化图形将是
H---J---M
/
A---B---F
\ /
P
但是,由于提交将用其引用标签,所以它看起来会更像(在ASCII艺术的限制内)
0.1.1---0.1.2---maint
/
0.0---0.1---master
\ /
topic
演示视频
Chuwei Lu制作了一个YouTube视频,展示了如何使用 git-big-picture
截图
感谢Graphviz,git-big-picture 可以输出漂亮的图像。
这是上面例子中的原始仓库
这是简化版本
我们还从以下真实世界示例中提供
依赖关系
Python >=3.8
Git (1.7.1有效)
Graphviz工具
pytest和Cram(仅用于运行测试)
安装
截至v0.10.1,您可以从PyPI安装它
https://pypi.ac.cn/project/git-big-picture/
$ pip install git-big-picture
或者,直接从Git克隆中运行它
$ git clone https://github.com/git-big-picture/git-big-picture.git
$ cd git-big-picture
$ python3 -m venv venv # creates a virtualenv
$ source venv/bin/activate # activates the virtualenv
$ pip install -e . # installs to the virtualenv
$ git-big-picture --help
或者,使用pip全局或仅对用户进行安装。
$ pip install .
(may need root privileges)
$ pip install --user .
Git集成
使用pip安装后,您可以通过确保在${PATH}查找过程中找到可执行文件git-big-picture,轻松地将此脚本集成为一个常规的Git命令。例如,如果您正在使用Bash,可以将以下行添加到您的~/.bashrc文件中:export PATH="${HOME}/.local/bin:${PATH}"。
然后,您可以像使用任何其他Git命令一样使用git big-picture(不带第一个连字符)
$ git big-picture -h
或者创建一个别名
$ git config --global alias.bp big-picture
$ git bp -h
内部
图操作是用Python编写的,并以易于书写的Graphviz语法输出图数据。这通过Graphviz的dot实用程序转换为图像。Graphviz支持多种图像格式,例如SVG和PDF。通过调用dot -V来检查Graphviz是否已安装。
用法
$ git-big-picture --help
usage: git-big-picture OPTIONS [REPOSITORY]
Visualize Git repositories
positional arguments:
REPOSITORY path to the Git working directory
(default: current directory)
options:
-h, --help show this help message and exit
--version show program's version number and exit
--pstats FILE run cProfile profiler writing pstats output to FILE
-d, --debug activate debug output
output options:
Options to control output and format
-f FMT, --format FMT set output format [svg, png, ps, pdf, ...]
--history-direction {downwards,leftwards,rightwards,upwards}
enforce a specific direction of history on Graphviz
(default: rightwards)
--simplify remove edges implied by transitivity using Graphviz
filter "tred" (default: do not remove implied edges)
-g, --graphviz output lines suitable as input for dot/graphviz
-G, --no-graphviz disable dot/graphviz output
-p, --processed output the dot processed, binary data
-P, --no-processed disable binary output
-v CMD, --viewer CMD write image to tempfile and start specified viewer
-V, --no-viewer disable starting viewer
-o FILE, --outfile FILE
write image to specified file
-O, --no-outfile disable writing image to file
-w SECONDS, --wait SECONDS
wait for SECONDS seconds before deleting the temporary
file that is opened using the viewer command (default:
2.0 seconds); this helps e.g. with viewer commands that
tell other running processes to open that file on their
behalf, to then shut themselves down
filter options:
Options to control commit/ref selection
-a, --all include all commits
-b, --branches show commits pointed to by branches
-B, --no-branches do not show commits pointed to by branches
-t, --tags show commits pointed to by tags
-T, --no-tags do not show commits pointed to by tags
-r, --roots show root commits
-R, --no-roots do not show root commits
-m, --merges include merge commits
-M, --no-merges do not include merge commits
-i, --bifurcations include bifurcation commits; a bifurcation commit is a
commit that is a parent to more than one other commits,
i.e. it marks the point where one or more new branches
came to life; bifurcation commits can also be thought of
as the counterpart of merge commits
-I, --no-bifurcations
do not include bifurcation commits
-c, --commit-messages
include commit messages on labels
-C, --no-commit-messages
do not include commit messages on labels
git-big-picture is software libre, licensed under the GPL v3 or later license.
Please report bugs at https://github.com/git-big-picture/git-big-picture/issues — thank you!
用法示例
有两个相关的选项组,输出选项和过滤选项。输出选项控制工具产生的输出和格式。过滤选项控制计算简化图时要包含哪些提交。
使用输出选项
生成当前Git仓库的PNG版本并保存到our-project.png
$ git-big-picture -o our-project.png
在~/git-repo中生成仓库的SVG(默认格式)图像,并在Firefox中查看结果
$ git-big-picture -v firefox ~/git-repo/
如果您指定了格式和带有扩展名的文件名,将使用文件扩展名
$ git-big-picture -f svg -o our-project.png
$ file our-project.png
our-project.png: PNG image data, 216 x 325, 8-bit/color RGB, non-interlaced
如果没有扩展名,仍然可以指定格式
$ git-big-picture -f pdf -o our-project
warning: Filename had no suffix, using format: pdf
否则将使用默认格式SVG
$ git-big-picture -o our-project
warning: Filename had no suffix, using default format: svg
如果您想使用替代查看器,请指定查看器和其格式
$ git-big-picture -f pdf -v xpdf
您还可以自动打开输出文件上的查看器
$ git-big-picture -v xpdf -o our-project.pdf
输出原始Graphviz语法
$ git-big-picture -g
输出原始Graphviz输出(即图像)
$ git-big-picture -p
然而,请注意,上面两个示例中的选项都是互斥的,并且与其他输出选项不兼容。
$ git-big-picture -g -p
fatal: Options '-g | --graphviz' and '-p | --processed' are mutually exclusive.
$ git-big-picture -g -v firefox
fatal: Options '-g | --graphviz' and '-p | --processed' are incompatible with other output options.
将Graphviz命令手动管道到dot实用程序
$ git-big-picture --graphviz ~/git-repo | dot -Tpng -o graph.png
使用过滤选项
三个选项--branches、--tags和--roots默认启用。您可以使用否定开关来关闭它们。这些使用短选项的大写等效项和前缀no-作为长选项。例如:使用-B | --no-branches来禁用显示分支。
显示所有有趣的提交,即显示合并和分叉
$ git-big-picture -i -m
仅显示根(禁用分支和标签)
$ git-big-picture -B -T
仅显示合并和分支(禁用标签)
$ git-big-picture -m -T
显示所有提交
$ git-big-picture -a
配置
可以使用标准的git config基础设施来配置git-big-picture。大多数命令行参数可以在一个big-picture部分中进行配置。例如,要配置firefox作为查看器
$ git config --global big-picture.viewer firefox
将在您的~/.gitconfig中创建以下部分和条目
[big-picture]
viewer = firefox
可以使用命令行否定参数来禁用通过命令行配置的设置。例如,如果您已经配置了上面的viewer并尝试使用-g | --graphviz开关,您将得到以下错误
$ git-big-picture -g
fatal: Options '-g | --graphviz' and '-p | --processed' are incompatible with other output options.
... 因为您已经配置了查看器。在这种情况下,使用否定选项 -V | --no-viewer 来从配置文件中禁用 viewer 设置
$ git-big-picture -g -V
开发
git-big-picture 使用 pre-commit,无论是在本地还是在 CI 中。要激活相同的本地 pre-commit Git 钩子,您可以这样做:
$ pip install pre-commit
$ pre-commit install --install-hooks
在此之后进行提交时,pre-commit 将运行在文件 .pre-commit-config.yaml 中配置的检查。
测试
Python 代码使用测试运行器 pytest 进行测试
$ ./test.py
命令行界面使用 Cram 进行测试
$ PATH="venv/bin:${PATH}" ./test.cram
调试
您可以使用 [-d | --debug] 开关进行调试
$ git-big-picture -d -v firefox
尽管调试输出有些稀疏...
性能分析
有两种方式可以分析 git-big-picture,使用内置的 --pstats 选项或使用 Python 模块 cProfile
使用 --pstats
$ git-big-picture --pstats=profile-stats -o graph.svg
... 将将性能分析输出写入 profile-stats。
使用 cProfile 分析脚本
$ python -m cProfile -o profile-stats git-big-picture -o graph.svg
在任何情况下,您都可以使用优秀的可视化工具 gprof2dot,顺便提一下,它也使用 Graphviz
$ gprof2dot -f pstats profile-stats | dot -Tsvg -o profile_stats.svg
变更日志
v1.3.0 — 2024-03-08
v1.2.2 — 2022-09-27
内部结构
修复 cram 测试对 grep >=3.8(#233)
v1.2.1 — 2022-03-26
v1.2.0 — 2022-03-01
v1.1.1 — 2021-01-20
v1.1.0 — 2021-01-20
v1.0.0 — 2021-01-13
安全修复
CVE-2021-3028 — 通过攻击者控制的分支名称修复本地代码执行 (#62)
新功能和改进
删除的功能
停止支持Python的淘汰版本(2.7、3.4、3.5) (#38)
已修复的错误
内部结构
将Git仓库的移动应用到所有URL,但Travis CI除外 (#40)
用GitHub Actions替换Travis CI (#41)
使CI涵盖对macOS的支持 (#44)
为开发和CI集成 pre-commit (#47, #53, #55)
删除空的 requirements.txt(《#52》)
从 optparse 迁移到 argparse(《#54》)
修复变量混淆问题(《#57》)
开始使用标准的 setuptools 入口点(《#58》)
解决废弃的测试代码(《#60》)
开始测量代码覆盖率(《#61》)
setup.py:在描述中将 ASCII “–” 替换为 “—”(破折号)(《#69》)
Readme:改进涉及人员部分(《#71》)
tests:覆盖命令行上的选项优先级(《#72》)
记录 1.0.0 版本的更改(《#74》)
发布版本 1.0.0(《#76》)
v0.10.1 — 2018-11-04
修复 PyPI 发布
v0.10.0 — 2018-11-04
v0.9.0 — 2012-11-20
rst-ify readme
修复图形搜索算法中的长期错误
修复从制表符到 4 个空格的长期转换错误
重构测试套件
删除旧的 --some 污染代码和选项
添加查找根、合并和分歧提交的能力
使用新选项重构命令行界面
使用 Cram 添加命令行界面测试
重构文档以反映更改
v0.8.0 — 2012-11-05
2010 年 3 月至今所有发展的快照
扩展了用于查看和格式的命令行选项
选项可以过滤所有、一些或装饰提交
为 Python 模块和命令行添加了简单的测试套件
许可证
根据 GPL v3 或更高版本授权,有关详细信息,请参阅文件 COPYING。
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。