我见过一些书籍和文章中有一些非常漂亮的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不工作。
其他回答
对于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不工作。
我建议tighttps://github.com/jonas/tig,一个更好的Git命令行工具。
您可以使用Homebrew在macOS上安装tig:
$ brew install tig
$ tig
我不知道有什么直接的工具,但也许你可以破解一个脚本,将数据导出为点格式,并用Graphviz渲染。
这里的许多答案都很好,但对于那些只想得到一个简单的一行到位的答案而不必设置别名或其他任何东西的人来说,这里是:
git log --all --decorate --oneline --graph
不是每个人都会一直做git日志,但当你需要它时,请记住:
“A Dog”=git log--all--decorate--oneline--graph
如果您输入
git config --global alias.adog "log --all --decorate --oneline --graph"
在命令提示符下,可以使用
git adog
即使您关闭并重新打开它,也可以从该提示中删除。
看着这段对话,我试着用我最喜欢的git可乐和git dag。
正在运行视图->DAG。。。从git-cola中删除并替换Log:master-with-都显示了一个包含所有分支的漂亮图形。