我见过一些书籍和文章中有一些非常漂亮的Git分支和提交的图表。如何制作Git历史的高质量可打印图像?
当前回答
Gitg是GNOME的Gitk和GitX的克隆(它也适用于KDE等),它显示了一个漂亮的彩色图形。
它正在积极开发(截至2012年)。它允许您按时间顺序或拓扑顺序对提交(图形节点)进行排序,并隐藏不会导致选定分支的提交。
它适用于大型存储库和复杂的依赖关系图。
示例屏幕截图,显示linuxgit和linux-2.6存储库:
其他回答
Sourcetree是一个非常好的工具。它确实打印出了一个好看的中等大小的历史和分支图:(以下是在一个实验性Git项目上完成的,只是为了查看一些分支)。支持Windows 7+和Mac OS X 10.6+。
我刚刚编写了一个工具,它可以使用HTML/Ccanvas生成一个漂亮的Git提交图。
并提供一个jQuery插件,使其易于使用。
[GitHub]https://github.com/tclh123/commits-graph
预览:
要获得更详细的文本输出,请尝试:
git log --graph --date-order -C -M --pretty=format:"<%h> %ad [%an] %Cgreen%d%Creset %s" --all --date=short
您可以在文件$HOME/.gitconfig中添加别名:
[alias]
graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short
对于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不工作。
我添加了三个自定义命令: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”显然在这个版本中首次出现。这是一个很好的补充,因为分支名称将获得不同的颜色。例如,这使得区分本地分支和远程分支更加容易。