我见过一些书籍和文章中有一些非常漂亮的Git分支和提交的图表。如何制作Git历史的高质量可打印图像?
当前回答
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生成它。
其他回答
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"
这是终端输出的外观:
稍微调整一下Slipp的精彩回答,你可以使用他的别名记录一个分支:
[alias]
lgBranch1 = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
lgBranch2 = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' --abbrev-commit
lg = !"git lg1"
你现在可以做的一切
git lgBranch1 <branch name>
甚至
git lgBranch1 --all
我刚刚编写了一个工具,它可以使用HTML/Ccanvas生成一个漂亮的Git提交图。
并提供一个jQuery插件,使其易于使用。
[GitHub]https://github.com/tclh123/commits-graph
预览:
这里是我的社区别名: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(GitGraph)
它生成Git存储库提交历史的PNG或SVG表示。