我见过一些书籍和文章中有一些非常漂亮的Git分支和提交的图表。如何制作Git历史的高质量可打印图像?


当前回答

我不知道有什么直接的工具,但也许你可以破解一个脚本,将数据导出为点格式,并用Graphviz渲染。

其他回答

我编写了一个web工具,用于将Git日志转换为漂亮的SVG图形:

Bit Booster-离线提交图形绘制工具

将git-log的输出--prey='%h|%p|%d'直接上载到工具中,然后单击“download-grap.svg”链接。

该工具是纯客户端的,因此您的Git数据不会与我的服务器共享。您还可以在本地保存HTML+JavaScript,并使用“file:///”URL运行它。它在Ubuntu 12.04(精确穿山甲)上的Chrome 48和Firefox 43上进行了验证。

它生成的HTML可以直接发布到任何页面(包括blogspot博客引擎!)。看看这里的一些博客帖子:

http://bit-booster.blogspot.ca/

下面是该工具生成的示例HTML文件的屏幕截图:

http://bit-booster.com/graph.html(工具)

稍微调整一下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

gitdags构建在TikZ&PGF之上,是一个小型LaTeX包,它允许您轻松地生成矢量图形提交图等。

自动生成现有存储库的提交图不是gitdags的目的;它生成的图形仅用于教育目的。

我经常使用它为Git问题的答案生成图形,作为ASCII提交图形的替代:

如何在master上执行错误修复并将其集成到不太稳定的分支中?git是如何提交修改工作的?为什么在我运行“Git checkout origin/<branch>”后,Git会告诉我“当前不在任何分支”?将主分支合并到分支和将分支合并到主分支之间有什么区别?Git rebase--保留合并失败

下面是这样一个图表的示例,演示了简单的重新设置基础的效果:

\documentclass{article}

\usepackage{subcaption}
\usepackage{gitdags}

\begin{document}

\begin{figure}
  \begin{subfigure}[b]{\textwidth}
    \centering
    \begin{tikzpicture}
      % Commit DAG
      \gitDAG[grow right sep = 2em]{
        A -- B -- { 
          C,
          D -- E,
        }
      };
      % Tag reference
      \gittag
        [v0p1]       % node name
        {v0.1}       % node text
        {above=of A} % node placement
        {A}          % target
      % Remote branch
      \gitremotebranch
        [origmaster]    % node name
        {origin/master} % node text
        {above=of C}    % node placement
        {C}             % target
      % Branch
      \gitbranch
        {master}     % node name and text 
        {above=of E} % node placement
        {E}          % target
      % HEAD reference
      \gitHEAD
        {above=of master} % node placement
        {master}          % target
    \end{tikzpicture}
    \subcaption{Before\ldots}
  \end{subfigure}

  \begin{subfigure}[b]{\textwidth}
    \centering
    \begin{tikzpicture}
      \gitDAG[grow right sep = 2em]{
        A -- B -- { 
          C -- D' -- E',
          {[nodes=unreachable] D -- E },
        }
      };
      % Tag reference
      \gittag
        [v0p1]       % node name
        {v0.1}       % node text
        {above=of A} % node placement
        {A}          % target
      % Remote branch
      \gitremotebranch
        [origmaster]    % node name
        {origin/master} % node text
        {above=of C}    % node placement
        {C}             % target
      % Branch
      \gitbranch
        {master}      % node name and text 
        {above=of E'} % node placement
        {E'}          % target
      % HEAD reference
      \gitHEAD
        {above=of master} % node placement
        {master}          % target
    \end{tikzpicture}
    \subcaption{\ldots{} and after \texttt{git rebase origin/master}}
  \end{subfigure}
  \caption{Demonstrating a typical \texttt{rebase}}
\end{figure}

\end{document}

基于我在回答相关问题时发现的Graphviz脚本,我黑了一个Ruby脚本,该脚本创建了Git存储库的摘要视图。它消除了所有的线性历史,只显示“有趣的”提交,即那些有多个父母、多个子女或由分支或标记指向的提交。下面是它为jQuery生成的图形片段:

git big picture和BranchMaster是类似的工具,它们试图通过仅显示标记、分支、合并等的关联方式,仅显示图形的高级结构。

这个问题还有其他选择。

有一个时髦的Git提交图作为Raphael web图形库的演示之一。

这个演示是静态的,但应该很容易获取代码并将静态数据交换为一组实时数据——我认为这只是JSON格式的Git提交数据。

演示在这里:http://dmitrybaranovskiy.github.io/raphael/github/impact.html