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


当前回答

尝试gitk或gitk——全部。但是,它没有打印/保存img功能。

其他回答

gitg:基于gtk的存储库查看器。这是新的,但有趣且有用。

我目前正在使用它。

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

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

这个问题还有其他选择。

更新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}
git -c core.pager='less -SRF' log --oneline --graph --decorate

这是我的终端变体,类似于这里的许多答案。我喜欢将传递的标志调整为较小,以防止换行。

为了快速访问,我将其设置为别名,因为命令有点麻烦。