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


当前回答

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

其他回答

我编写了一个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(工具)

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

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

$ brew install tig
$ tig

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}

这是我对此事的看法:

截图:

用法:

githist-显示当前分支的历史记录

githist--all-显示所有分支(包括remotes)的图形

git-hist-master-devel-显示两个或多个分支之间的关系

git-hist--分支-显示所有本地分支

添加--按拓扑顺序对提交进行排序,而不是按日期排序(此别名中的默认值)

优点:

看起来就像普通的装饰,所以不同的分支名称使用不同的颜色添加提交人电子邮件添加提交相对日期和绝对日期按日期排序提交

设置:

git config --global alias.hist "log --graph --date-order --date=short \
--pretty=format:'%C(auto)%h%d %C(reset)%s %C(bold blue)%ce %C(reset)%C(green)%cr (%cd)'"

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

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

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

预览: