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


当前回答

我刚刚编写了一个工具,它可以使用HTML/Ccanvas生成一个漂亮的Git提交图。

并提供一个jQuery插件,使其易于使用。

[GitHub]https://github.com/tclh123/commits-graph

预览:

其他回答

Gitg是GNOME的Gitk和GitX的克隆(它也适用于KDE等),它显示了一个漂亮的彩色图形。

它正在积极开发(截至2012年)。它允许您按时间顺序或拓扑顺序对提交(图形节点)进行排序,并隐藏不会导致选定分支的提交。

它适用于大型存储库和复杂的依赖关系图。

示例屏幕截图,显示linuxgit和linux-2.6存储库:

我刚刚编写了一个工具,它可以使用HTML/Ccanvas生成一个漂亮的Git提交图。

并提供一个jQuery插件,使其易于使用。

[GitHub]https://github.com/tclh123/commits-graph

预览:

我建议tighttps://github.com/jonas/tig,一个更好的Git命令行工具。

您可以使用Homebrew在macOS上安装tig:

$ brew install tig
$ tig

更新2:我发布了Git中可视化分支拓扑问题的改进版本,因为它更合适。该版本包含lg3,它显示了作者和提交者的信息,因此您确实应该检查一下。出于历史原因(我承认)留下这个答案,尽管我真的很想删除它。

我的两分钱:我通常在~/.gitconfig文件中使用两个别名:

[alias]
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --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(dim white)- %an%C(reset)' --all
lg = !"git lg1"

git lg/git lg1如下所示:

git lg2看起来像这样:


(注意:现在有更多适用于此问题的答案,例如fracz、Jubobs或Harry Lee的!)

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}