我见过一些书籍和文章中有一些非常漂亮的Git分支和提交的图表。如何制作Git历史的高质量可打印图像?
当前回答
试试dita。它可以将任何ASCII图转换为图像。虽然它的设计没有考虑Git分支,但我对结果印象深刻。
源(txt文件):
+--------+
| hotfix |
+---+----+
|
--*<---*<---*
^
|
\--*<---*
|
+---+----+
| master |
+--------+
命令:
java -jar ditaa0_9.jar ascii-graph.txt
结果:
它还支持背景色、虚线、不同形状等。请参见示例。
其他回答
文件~/.oh-my-zsh/plugins/git/git.plugin.zsh中的一些别名:
gke='\gitk --all $(git log -g --pretty=%h)'
glg='git log --stat'
glgg='git log --graph'
glgga='git log --graph --decorate --all'
glgm='git log --graph --max-count=10'
glgp='git log --stat -p'
glo='git log --oneline --decorate'
glog='git log --oneline --decorate --graph'
gloga='git log --oneline --decorate --graph --all'
glol='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
glola='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --all'
Gitg是GNOME的Gitk和GitX的克隆(它也适用于KDE等),它显示了一个漂亮的彩色图形。
它正在积极开发(截至2012年)。它允许您按时间顺序或拓扑顺序对提交(图形节点)进行排序,并隐藏不会导致选定分支的提交。
它适用于大型存储库和复杂的依赖关系图。
示例屏幕截图,显示linuxgit和linux-2.6存储库:
我在~/.gitconfig中有这个git日志别名来查看图形历史:
[alias]
l = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
有了这一点,git l将输出如下内容:
在Git2.12+中,您甚至可以使用log.graphColors配置选项自定义图形的线条颜色。
至于日志的格式,它类似于--oneline,添加了作者名(尊重.mailmap)和相对作者日期。请注意,在Git>=1.8.3中支持%C(auto)语法,告诉Git使用提交散列等的默认颜色。
我添加了三个自定义命令:gittree、gitstree和gitvtree。我会按顺序检查它们。
[alias]
tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n %C(black)[%cr]%C(reset) %x09%C(black)%an: %s %C(reset)'
使用gitstree和gitvtree,我使用Bash来帮助格式化。
[alias]
logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++ %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
stree = !bash -c '" \
while IFS=+ read -r hash time branch message; do \
timelength=$(echo \"$time\" | sed -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);"'
[alias]
logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++ %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
vtree = !bash -c '" \
while IFS=+ read -r hash time branch message; do \
timelength=$(echo \"$time\" | sed -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);"'
这适用于Git 1.9a版本。颜色值“auto”显然在这个版本中首次出现。这是一个很好的补充,因为分支名称将获得不同的颜色。例如,这使得区分本地分支和远程分支更加容易。
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生成它。