我见过一些书籍和文章中有一些非常漂亮的Git分支和提交的图表。如何制作Git历史的高质量可打印图像?
当前回答
对于OS X用户,我采用了@gospes示例,并针对gsed(通过Homebrew安装的gnu-sed)对其进行了轻微修改,并调整了颜色(以使用黑色背景,但不确定原始示例可能会以示例中的方式呈现,因为它在具有黑色背景的终端上指定了黑色文本)。
[alias]
# tree, vtree, stree support
logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(bold black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++ %C(bold black)%an%C(reset)%C(bold black): %s%C(reset)'
tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n %C(bold black)[%cr]%C(reset) %x09%C(bold black)%an: %s %C(reset)'
stree = !bash -c '" \
while IFS=+ read -r hash time branch message; do \
timelength=$(echo \"$time\" | gsed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\"); \
timelength=$(echo \"16+${#time}-${#timelength}\" | bc); \
printf \"%${timelength}s %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"\"; \
done < <(git logx && echo);"' | less -r
vtree = !bash -c '" \
while IFS=+ read -r hash time branch message; do \
timelength=$(echo \"$time\" | gsed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\"); \
timelength=$(echo \"16+${#time}-${#timelength}\" | bc); \
printf \"%${timelength}s %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"$message\"; \
done < <(git logx && echo);"' | less -r
OS X的关键是首先安装GNU sed(它具有-r选项)。使用Homebrew最容易做到这一点,它不会覆盖已安装的sed系统,而是将GNU sed安装为“gsed”。我希望这有助于@SlippD.Thompson,他在上面评论了OS X不工作。
其他回答
这里是我的社区别名:gitls。使用gitls,您可以查看图形,每次提交只覆盖一行。一切都是彩色的,并带有有用的信息。您还可以检查其他分支上的提交历史记录:
git config --global alias.ls '!f() { git log $1 --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%ae,%ar]" --decorate --graph; }; f'
用法:
# shows commits graph on the current branch
git ls
# shows commits graph on the develop branch
git ls develop
以下是图表视图:
Gitgraph.js允许在没有存储库的情况下绘制漂亮的Git分支。只需编写一个JavaScript代码来配置分支和提交并在浏览器中呈现。交互式文档可用。
var gitGraph = new GitGraph({
template: "blackarrow",
mode: "compact",
orientation: "horizontal",
reverseArrow: true
});
var master = gitGraph.branch("master").commit().commit();
var develop = gitGraph.branch("develop").commit();
master.commit();
develop.commit().commit();
develop.merge(master);
或使用地铁模板:
或者使用提交消息、作者和标签:
用JSFiddle测试它。
通过@bsara使用GitGraper生成它。
如果您的存储库位于GitLab上,您可以使用它的图形表示,因为它在浏览器中呈现为SVG。
转到存储库的图形视图,例如。,https://gitlab.com/gitlab-org/gitter/webapp/network/develop将图形向下滚动到底部(它会延迟加载提交!)使用浏览器的检查器将SVG元素复制到新文件在您选择的渲染器中打开它,例如Inkscape
git forest是一个优秀的Perl脚本,我已经使用了一年多,我几乎不再直接使用git log命令。
以下是我喜欢这个剧本的一些地方:
它使用Unicode字符在图形中绘制线条,使图形线条看起来更加连续。您可以将--reverse与图形输出相结合,这在常规gitlog命令中是不可能的。它在内部使用gitlog获取提交列表,因此传递给gitlog的所有选项也可以传递给该脚本。
我有一个使用git forest的别名,如下所示:
[alias]
tree = "forest --pretty=format:\"%C(red)%h %C(magenta)(%ar) %C(blue)%an %C(reset)%s\" --style=15 --reverse"
这是终端输出的外观:
我不知道有什么直接的工具,但也许你可以破解一个脚本,将数据导出为点格式,并用Graphviz渲染。