漂亮的git分支图

kro*_*old 1290 git git-log

我已经看到一些书籍和文章有一些非常漂亮的git分支和提交图.如何制作git历史的高质量可打印图像?

Sli*_*son 1770

更新:这个答案得到了比应有的更多的关注.它最初发布是因为我认为图形看起来不错,它们可以在Illustrator中用于出版物 - 并且没有更好的解决方案.但是现在存在更多适用于这个Q的答案,比如fracz 's,Jubobs '或Harry Lee 's!请尽快投票!

更新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"
Run Code Online (Sandbox Code Playgroud)

git lg/ git lg1看起来像这样:
git lg1

并且git lg2看起来是这样的:
git lg2

  • 是的.正常和明亮/大胆的颜色是:黑色`#202020` /`#555555`,红色:`#5d1a14` /`#da4939`,绿色:`#424e24` /`#a5c261`,黄色:`#6f5028`/`#ffc66d`,蓝色:`#263e4e` /`#6d9cbe`,洋红色:`#3e1f50` /`#a256c7`,青色:`#234e3f` /`#62c1a1`,白色:`#979797` /` #ffffff`. (34认同)
  • 我将`%C(auto)`修饰符添加到refnames(`%d`)以获得更好的颜色.请参阅http://stackoverflow.com/questions/5889878/color-in-git-log/16844346#16844346 (5认同)
  • @Turbo:对我来说,终端应用程序(Terminal.app)的配置文件设置中的颜色是可以更改的.您正在使用的终端应用程序可能支持也可能不支持更改为给定ANSI颜色显示的颜色.此外,使用option-shift- [连字符 - 减键]创建了破折号(精确的破折号).我想我错误地认为所有当前的平台都使用Unicode. (3认同)
  • 你的`--date = relative`和`--abbrev-commit`是多余的,因为你分别明确地使用`%cr`和`%h`. (3认同)
  • 很好的答案.我修改了命令看起来更像是--oneline --decorate的输出`lg = log --graph --abbrev-commit --decorate --format = format:'%C(黄色)%h% C(复位)%C(自动)%d%C(复位)%C(正常)%s%C(复位)%C(暗白色)%和%C(复位)%C(暗蓝色)(%ar )%C(重置)' - all` (2认同)
  • 我仍然认为这是最好的答案,因为它不需要任何额外的工具,它是裸露的 git。 (2认同)

Pat*_*パトシ 1046

这里的许多答案都很棒,但对于那些只需要一个简单的一行到点答案而不必设置别名或任何额外内容的人来说,这里是:

git log --all --decorate --oneline --graph
Run Code Online (Sandbox Code Playgroud)

不是每个人都会一直在做git log,但是当你需要它时,请记住:

" "= GIT中的日志- 一个 LL - d ecorate - ö neline - 拉夫

在此输入图像描述

  • `git config --global alias.adog"log --all --decorate --oneline --graph"` (210认同)
  • 我认为现在默认包含“--decorate”。但无论如何我都会记住这个缩写! (8认同)
  • 最佳答案。感谢您放心。 (6认同)
  • 我一直在寻找`--all`很久了,我要哭(T_T)谢谢! (3认同)
  • 不同选项的用途摘要:--all = 假设 refs/ 中的所有引用都在命令行中列为 commit>。--no-decorate, --decorate[=short|full|no] = 打印出显示的任何提交的引用名称。如果指定了short,则不会打印引用名称前缀refs/heads/、refs/tags/ 和refs/remotes/。如果指定了 full,则将打印完整的 ref 名称(包括前缀)。--oneline = 这是一起使用的“--pretty=oneline --abbrev-commit”的简写。--graph= 绘制提交历史的基于文本的图形表示 (2认同)
  • --oneline 是在 Git 1.6.3 中引入的:https://github.com/git/git/blob/53f9a3e157dbbc901a02ac2c73346d375e24978c/Documentation/RelNotes/1.6.3.txt#L69 --pretty=oneline 1.6 之前的 Git 版本.3 (2认同)
  • 这个答案给我带来了快乐,也提供了信息 (2认同)
  • 我更喜欢“All Dogs”`git log --all --decorate --oneline --graph --stat` (2认同)

keo*_*keo 345

对于文本输出,您可以尝试:

git log --graph --abbrev-commit --decorate --date=relative --all
Run Code Online (Sandbox Code Playgroud)

要么:

git log --graph --oneline --decorate --all
Run Code Online (Sandbox Code Playgroud)

或:这是 绘制DAG图的graphviz别名.

我亲自使用gitx,gitk --allgitnub.

  • 我会添加`--abbrev-commit --decorate`,然后它就完美了! (14认同)
  • -abeline暗示了--abbrev-commit,不是吗? (5认同)
  • @dwineman是的,如果使用`--oneline`,你不需要`--abbrev-commit` (4认同)
  • 似乎在你的第二行`git log --graph --oneline --decorate --date = relative --all`中,`--date`参数是无用的.我可以看到日志中没有显示日期. (2认同)

fra*_*acz 230

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);
Run Code Online (Sandbox Code Playgroud)

使用Gitgraph.js生成的示例图

或者使用metro模板:

GitGraph.js地铁主题

或者使用提交消息,作者和标签:

带有提交消息的GitGraph

JSFiddle测试它.

由@bsara 用Git Grapher生成它.

  • 箭头应该指向父母,但不是儿童. (14认同)
  • 关于箭头方向,来自docs:*@param {Boolean} [options.reverseArrow = false] - 如果为true,则使箭头指向祖先 (5认同)
  • @Jubobs:好点.这是人们试图理解Git的一个共同障碍:他们考虑的是时间顺序而不是继承.明确表示(几乎)git中的所有内容都与先前的内容有关,这有助于所有其他内容的到位. (4认同)
  • 是的,那真是太神奇了!将其发布到小提琴http://jsfiddle.net/guan1oz1/中,以便您可以立即对其进行测试。 (2认同)
  • @fracz:这真的很酷。谢谢。不过,有一个建议:请注意,即使测试网页只显示没有文本,如果下载并在本地打开,gitgraph.js 也会显示提交消息、标签等。-- 我建议这样做是因为,一开始我认为它不能显示文本,因此不能满足我的需求。幸运的是,我没有放弃,并将 gitgraph.js 下载到我的笔记本电脑上。事实证明,实际输出非常惊人,正是我想要的。:) (2认同)
  • 仅供参考,在看完这篇文章并使用gitgraph.js后,我决定创建一个基本上将UI放到gitgraph.js的小工具.它还没有完成,用户界面不是我想要它的地方,但欢迎捐款!看看:https://github.com/bsara/git-grapher (2认同)
  • 这只是为了演示,而不是为了生成图表或真正的 git 历史记录,这是最初的问题。 (2认同)

jub*_*0bs 114

基于TikZ和PGF构建,gitdags是一个小型的LaTeX软件包,可以让您毫不费力地生成矢量图形提交图等等.

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

作为ASCII提交图的替代方法,我经常用它来为我对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}
Run Code Online (Sandbox Code Playgroud)

  • 我花了一些时间来完成这项工作,所以我写了一个循序渐进的指南,如何[在Ubuntu 14.04上从头开始使用gitdags](http://chrisfreeman.github.io/gitdags_install.html) (5认同)
  • @看起来很棒!我还想了解一下如何使用它:考虑一个根本没有安装 LaTeX 的 Windows 用户。如何从头开始制作图表? (2认同)

Mec*_*ail 75

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

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

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

示例截图,显示linux-git和linux-2.6存储库:

Linux的混帐

Linux的2.6


nop*_*ole 60

SourceTree是一个非常好的.它打印出一个外观漂亮和中等大小的历史记录和分支图:(以下是在一个实验性的Git项目上完成,只是为了看到一些分支).支持Windows 7+和Mac OS X 10.6+.

在此输入图像描述

http://www.sourcetreeapp.com/

  • 然后在卸载后不要忘记整理您之前授予的Google安全权限:https://myaccount.google.com/security - >已连接的应用和网站 - >与您的帐户关联的应用 - >管理应用 (3认同)

Har*_*Lee 58

我刚刚编写了一个工具,可以使用HTML/Canvas生成漂亮的git提交图.

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

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

预习:

预习

  • @Olga我只是将后端代码添加到我的仓库中.你可以在github上查看[it](https://github.com/tclh123/commits-graph/blob/master/git/commits_graph.py). (3认同)

Tux*_*ude 55

git-forest是一个很好的perl脚本,我已经使用了一年多,我几乎git log不再直接使用命令.

这些是我喜欢这个脚本的一些东西:

  • 它使用unicode字符在图形中绘制线条,从而为图形线条提供更连续的外观.
  • 您可以结合--reverse图形输出,这是常规git log命令无法实现的.
  • 它在git log内部用于获取提交列表,因此您传递给的所有选项git log也可以传递给此脚本.

我有一个别名使用git-forest如下:

[alias]
tree = "forest --pretty=format:\"%C(red)%h %C(magenta)(%ar) %C(blue)%an %C(reset)%s\" --style=15 --reverse"
Run Code Online (Sandbox Code Playgroud)

这是终端上输出的样子:

在此输入图像描述

  • @ void.pointer - 是的,它不会,因为git-forest是一个perl脚本并且具有perl模块依赖性.在cygwin下运行git并安装所需的perl模块可能是你在Windows上真正想要的最佳选择:) (3认同)

G. *_*ies 48

我写了一个web工具,用于将git日志转换为漂亮的SVG图: Bit-Booster - 离线提交图绘制工具

将输出git log --pretty='%h|%p|%d'直接上传到工具中,然后单击"下载graph.svg"链接.

该工具是纯客户端的,因此您的Git数据都不会与我的服务器共享.您还可以在本地保存HTML + JS并使用"file:///"URL运行它.在Ubuntu 12.04上的Chrome 48和Firefox 43上验证.

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

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

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

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

  • @Jay 似乎颜色反映了该特定分支的缩进级别,并且该分支可能会移动到另一列并因此更改 color.s (2认同)

Mat*_*nry 44

基于我在相关问题的答案中找到的Graphviz脚本,我已经破解了一个ruby脚本,它创建了一个git存储库的摘要视图.它省略了所有线性历史记录,只显示"有趣"提交,即具有多个父项,多个子项或由分支或标记指向的提交.这是为jquery生成的图表的片段:

jquery样本

git-big-pictureBranchMaster是类似的工具,它们只通过显示标签,分支,合并等的相关性来尝试仅显示图形的高级结构.

这个问题还有一些选择.

  • 我试过这个,但是无法让dot与我们的repo的输出正常工作(42个分支,175个标签,42.000个提交)......太糟糕了...这正是我想要的! (2认同)

Dus*_*tin 37

取决于他们的样子.我使用gitx制作这样的照片:

简单的情节

您可以git log --graph在24路章鱼合并中与gitk进行比较(最初来自http://clojure-log.n01se.net/date/2008-12-24.html):

24路git章鱼合并. 原始网址为<code> http://lwn.net/images/ns/kernel/gitk-octopus.png </ code>

  • 这很有趣......我发誓我听说你说"24路章鱼合并"! (47认同)
  • 出于好奇,有没有人试图将GitX(或其他GUI git工具)绘制例程提取到一个独立的可执行文件中?如果我没有弄错的话,让Cocoa绘制成矢量PDF文件并不困难,并且会满足OP对高Q可打印图像的需求. (4认同)

gos*_*pes 37

我已经添加了三个自定义命令:git tree,git streegit vtree.我会按顺序检查它们.

[alias]
    tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n         %C(black)[%cr]%C(reset)  %x09%C(black)%an: %s %C(reset)'
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

随着git streegit vtree我使用bash来帮助格式化.

[alias]
    logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
    stree = !bash -c '"                                                                             \
        while IFS=+ read -r hash time branch message; do                                            \
            timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\");     \
            timelength=$(echo \"16+${#time}-${#timelength}\" | bc);                                 \
            printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"\";          \
        done < <(git logx && echo);"'
Run Code Online (Sandbox Code Playgroud)

git_stree


[alias]
    logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++       %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
    vtree = !bash -c '"                                                                             \
        while IFS=+ read -r hash time branch message; do                                            \
            timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\");     \
            timelength=$(echo \"16+${#time}-${#timelength}\" | bc);                                 \
            printf \"%${timelength}s    %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"$message\";  \
        done < <(git logx && echo);"'
Run Code Online (Sandbox Code Playgroud)

git_vtree


编辑:这适用于git版本1.9a.颜色值'auto'显然是在这个版本中首次亮相.这是一个很好的补充,因为分支名称将获得不同的颜色.这使得更容易区分本地和远程分支.


one*_*ion 36

一个漂亮干净的类似于表格的 shell 的 Git 图形输出

除了图树之外,通常还有散列

除了图树之外,通常还有散列

或者在一个额外的列中

或者在一个额外的列中

编辑:您想在不阅读所有解释的情况下立即开始吗?跳转到编辑 6

信息:对于外壳的更像分支的彩色版本,另见我的第二个答案(/sf/answers/4427719481/)。

到目前为止,在这个问题的所有答案中,没有一个显示外壳的干净的类似表格的输出。最接近的是来自我开始的福音书的这个答案

我的方法的核心点是只计算向用户显示的树字符。然后用空格将它们填充到个人长度。

除了 Git,你还需要这些工具

  • 格雷普
  • 粘贴
  • 打印输出
  • sed
  • 序列
  • tr
  • 厕所

主要适用于任何 Linux 发行版。

代码片段是

while IFS=+ read -r graph hash time branch message;do

  # Count needed amount of white spaces and create them
  whitespaces=$((9-$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)))
  whitespaces=$(seq -s' ' $whitespaces|tr -d '[:digit:]')

  # Show hashes besides the tree ...
  #graph_all="$graph_all$graph$(printf '%7s' "$hash")$whitespaces \n"

  # ... or in an own column
  graph_all="$graph_all$graph$whitespaces\n"
  hash_all="$hash_all$(printf '%7s' "$hash")  \n"

  # Format all other columns
  time_all="$time_all$(printf '%12s' "$time") \n"
  branch_all="$branch_all$(printf '%15s' "$branch")\n"
  message_all="$message_all$message\n"
done < <(git log --all --graph --decorate=short --color --pretty=format:'+%C(bold 214)%<(7,trunc)%h%C(reset)+%C(dim white)%>(12,trunc)%cr%C(reset)+%C(214)%>(15,trunc)%d%C(reset)+%C(white)%s%C(reset)' && echo);

# Paste the columns together and show the table-like output
paste -d' ' <(echo -e "$time_all") <(echo -e "$branch_all") <(echo -e "$graph_all") <(echo -e "$hash_all") <(echo -e "$message_all")
Run Code Online (Sandbox Code Playgroud)

为了计算我们使用的所需空格

  sed -nl1000 'l' <<< "$graph"
Run Code Online (Sandbox Code Playgroud)

获取所有字符(直到每行 1000 个)而不是仅选择树字符:* | / \ _ 和空格与

  grep -Eo '\\\\|\||\/|\ |\*|_'
Run Code Online (Sandbox Code Playgroud)

最后计算它们并从我们选择的长度值中减去结果,在示例中为 9。

为了产生我们使用的计算出的空白数量

  seq -s' ' $whitespaces
Run Code Online (Sandbox Code Playgroud)

并截断位置编号

  tr -d '[:digit:]'
Run Code Online (Sandbox Code Playgroud)

然后将它们添加到我们图形线的末尾。就是这样!

Git 有一个很好的选项来格式化输出说明符的长度语法'%><(amount_of_characters,truncate_option)',它从左边的 '>' 或右边的 '<' 边添加空格,并且可以截断开头 'ltrunc'、中间的 'mtrunc' 或结束'trunc'。

这是重要的是printf的CMD的上述使用相同的长度值相应的GIT中柱。

玩得开心,根据您的需要设计您自己的干净的类似表格的输出。

额外的:

要获得正确的长度值,您可以使用以下代码段

while read -r graph;do
    chars=$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)
    [[ $chars -gt ${max_chars:-0} ]] && max_chars=$chars
done < <(git log --all --graph --pretty=format:' ')
Run Code Online (Sandbox Code Playgroud)

并使用 $max_chars 作为上面的正确长度值。

编辑 1:刚刚注意到在 git 树中也使用了下划线字符,并相应地编辑上面的代码片段。如果缺少其他字符,请发表评论。

编辑 2:如果你想去掉分支和标签条目周围的括号,只需在 git 命令中使用“%D”而不是“%d”,就像在编辑 3 中一样。

编辑 3:也许“自动”颜色选项是您最喜欢的分支和标签条目?

Git 无括号自动色头和标签 tablelike shell 输出

更改 git 命令的这一部分(颜色214

%C(214)%>(15,trunc)%D%C(reset)
Run Code Online (Sandbox Code Playgroud)

汽车

%C(auto)%>(15,trunc)%D%C(reset)
Run Code Online (Sandbox Code Playgroud)

编辑 4:或者你喜欢你自己的那部分颜色混合,一个带有闪烁头部的花哨输出?

Git 树花式样式的 tablelike 输出

为了能够首先设置头部、分支名称和标签的样式,我们需要像编辑 3 一样在我们的 git 命令中使用“自动”颜色选项。

然后我们可以通过添加这 3 行来用我们自己的颜色值替换已知的颜色值

 # branch name styling
 branch=${branch//1;32m/38;5;214m}
 # head styling
 branch=${branch//1;36m/3;5;1;38;5;196m}
 # tag styling
 branch=${branch//1;33m/1;38;5;222m}
Run Code Online (Sandbox Code Playgroud)

就在行前

 branch_all="$branch_all$(printf '%15s' "$branch")\n"
Run Code Online (Sandbox Code Playgroud)

在我们的代码片段中。替换值产生上面的颜色。

例如 head 的替换值是

3;5;1;38;5;196
Run Code Online (Sandbox Code Playgroud)

其中 3; 代表斜体,5;闪烁,1;38;5;196 表示颜色。有关更多信息,请从这里开始。注意:此行为取决于您最喜欢的终端,因此可能无法使用。

但是您可以选择您喜欢的任何颜色值。

git 颜色值和 ANSI 等效值概述

在此处输入图片说明

您可以在此处找到带有git color/style 选项的列表。

如果您需要控制台上的输出以获得准确的颜色(上图由 Stack Overflow 缩小),您可以使用以下命令生成输出

for ((i=0;i<=255;i++));do
  while IFS='+' read -r tree hash;do
    echo -e "$(printf '%-10s' "(bold $i)") $hash  $(sed -nl500 'l' <<< "$hash"|grep -Eom 1 '[0-9;]*[0-9]m'|tr -d 'm')"
  done < <(git log --all --graph --decorate=short --color --pretty=format:'+%C(bold '$i')%h%C(reset)'|head -n 1)
done
Run Code Online (Sandbox Code Playgroud)

在您的 Git 项目路径中,它使用来自您的 Git 日志输出的第一次提交。

编辑 5:正如成员“Andras Deak”所提到的,有一些方法可以使用此代码:

1) 作为别名

别名不接受参数但函数可以,因此只需在您的 .bashrc 中定义

   function git_tably () {
     unset branch_all graph_all hash_all message_all time_all max_chars

     ### add here the same code as under "2) as a shell-script" ###

   }
Run Code Online (Sandbox Code Playgroud)

并直接在您的 git 项目路径下或从您想要的任何地方使用您的 git 项目路径作为第一个参数调用函数 git_tably(派生自 table-like)。

2)作为shell脚本

我将它与选项一起使用,将 Git 项目目录作为第一个参数传递给它,或者如果为空,则像正常行为一样采用工作目录。总的来说,我们有

# Edit your color/style preferences here or use empty values for git auto style
tag_style="1;38;5;222"
head_style="1;3;5;1;38;5;196"
branch_style="38;5;214"

# Determine the max character length of your git tree
while IFS=+ read -r graph;do
  chars_count=$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)
  [[ $chars_count -gt ${max_chars:-0} ]] && max_chars=$chars_count
done < <(cd "${1:-"$PWD"}" && git log --all --graph --pretty=format:' ')

# Create the columns for your preferred table-like git graph output
while IFS=+ read -r graph hash time branch message;do

  # Count needed amount of white spaces and create them
  whitespaces=$(($max_chars-$(sed -nl1000 'l' <<< "$graph" | grep -Eo '\\\\|\||\/|\ |\*|_' | wc -l)))
  whitespaces=$(seq -s' ' $whitespaces|tr -d '[:digit:]')

  # Show hashes besides the tree ...
  #graph_all="$graph_all$graph$(printf '%7s' "$hash")$whitespaces \n"

  # ... or in an own column
  graph_all="$graph_all$graph$whitespaces\n"
  hash_all="$hash_all$(printf '%7s' "$hash")  \n"

  # Format all other columns
  time_all="$time_all$(printf '%12s' "$time") \n"
  branch=${branch//1;32m/${branch_style:-1;32}m}
  branch=${branch//1;36m/${head_style:-1;36}m}
  branch=${branch//1;33m/${tag_style:-1;33}m}
  branch_all="$branch_all$(printf '%15s' "$branch")\n"
  message_all="$message_all$message\n"

done < <(cd "${1:-"$PWD"}" && git log --all --graph --decorate=short --color --pretty=format:'+%C(bold 214)%<(7,trunc)%h%C(reset)+%C(dim white)%>(12,trunc)%cr%C(reset)+%C(auto)%>(15,trunc)%D%C(reset)+%C(white)%s%C(reset)' && echo);

# Paste the columns together and show the table-like output
paste -d' ' <(echo -e "$time_all") <(echo -e "$branch_all") <(echo -e "$graph_all") <(echo -e "$hash_all") <(echo -e "$message_all")
Run Code Online (Sandbox Code Playgroud)

3) 作为 git 别名

也许最舒服的方法是在你的 .gitconfig 中添加一个 git 别名

[color "decorate"]
    HEAD = bold blink italic 196
    branch = 214
    tag = bold 222

[alias]
    count-log = log --all --graph --pretty=format:' '
    tably-log = log --all --graph --decorate=short --color --pretty=format:'+%C(bold 214)%<(7,trunc)%h%C(reset)+%C(dim white)%>(12,trunc)%cr%C(reset)+%C(auto)%>(15,trunc)%D%C(reset)+%C(white)%s%C(reset)'
    tably     = !bash -c '"                                                                                                    \
                  while IFS=+ read -r graph;do                                                                                 \
                    chars_count=$(sed -nl1000 \"l\" <<< \"$graph\" | grep -Eo \"\\\\\\\\\\\\\\\\|\\||\\/|\\ |\\*|_\" | wc -l); \
                    [[ $chars_count -gt ${max_chars:-0} ]] && max_chars=$chars_count;                                          \
                  done < <(git count-log && echo);                                                                             \
                  while IFS=+ read -r graph hash time branch message;do                                                        \
                    chars=$(sed -nl1000 \"l\" <<< \"$graph\" | grep -Eo \"\\\\\\\\\\\\\\\\|\\||\\/|\\ |\\*|_\" | wc -l);       \
                    whitespaces=$(($max_chars-$chars));                                                                        \
                    whitespaces=$(seq -s\" \" $whitespaces|tr -d \"[:digit:]\");                                               \
                    graph_all=\"$graph_all$graph$whitespaces\n\";                                                              \
                    hash_all=\"$hash_all$(printf \"%7s\" \"$hash\")  \n\";                                                     \
                    time_all=\"$time_all$(printf \"%12s\" \"$time\") \n\";                                                     \
                    branch_all=\"$branch_all$(printf \"%15s\" \"$branch\")\n\";                                                \
                    message_all=\"$message_all$message\n\";                                                                    \
                  done < <(git tably-log && echo);                                                                             \
                  paste -d\" \" <(echo -e \"$time_all\") <(echo -e \"$branch_all\") <(echo -e \"$graph_all\")                  \
                                <(echo -e \"$hash_all\") <(echo -e \"$message_all\");                                          \
                '"
Run Code Online (Sandbox Code Playgroud)

不仅仅是git tably在任何项目路径下调用。

Git 非常强大,您可以直接更改头部、标签等,如上图所示并取自此处

另一个花哨的选择是选择您最喜欢的树颜色

[log]
    graphColors = bold 160, blink 231 bold 239, bold 166, bold black 214, bold green, bold 24, cyan
Run Code Online (Sandbox Code Playgroud)

这让你看起来很疯狂,但总是像表格一样 git log 输出

fanciest_git_tree_tablelike_image

眨眼太多了!只是为了证明什么是可能的。指定颜色太少会导致颜色重复。

只需单击一下即可获得完整的 .gitconfig 参考。

编辑 6由于您的赞成票,我改进了代码段。现在,您几乎可以使用任何 git log 命令来提供它,而不必再修改代码。尝试一下!

它是如何工作的?

  • 像往常一样在 .gitconfig 中定义 Git 日志命令(格式如下)
  • 定义一个正树列号,其中显示 git 图(可选)

然后就打电话

    git tably YourLogAlias

在任何 git 项目路径下或

    git tably YourLogAlias TreeColNumber

其中 TreeColNumber 覆盖了上面始终定义的值。

    git tably YourLogAlias | less -r

将通过管道将输出减少,这对于巨大的历史非常有用。

您的 Git 日志别名必须遵循以下格式规则:

  • 每列必须由您必须选择的列分隔符指示,如果不唯一可能会导致问题

    ^...format:'^%h^%cr^%s'树中,哈希,每次的结果和一个提交列

  • 在您必须使用%><(<N>[,ltrunc|mtrunc|trunc])trunc 选项之一的日志命令中的每个提交占位符之前

    (语法解释见https://git-scm.com/docs/pretty-formats),

    但是,可以在没有它的情况下使用任何换行符的最后一个提交占位符

    IE ...format:'^%<(7,trunc)%h^%<(12,trunc)%cr^%s'

  • 如果需要装饰像多余的字符(committer: <>)

    ...%C(dim white)(committer: %cn% <%ce>)%C(reset)...

    要获得类似表格的输出,它们必须直接在提交占位符之前和之后写入

    IE ...%C(dim white)%<(25,trunc)(committer: %cn%<(25,trunc) <%ce>)%C(reset)...

  • 使用列颜色喜欢%C(white)...%C(rest)需要--color彩色输出的选项

    IE ...--color...format:'^%C(white)%<(7,trunc)%h%C(rest)...

  • 如果您使用该--stat选项或类似选项,请%n在末尾添加一个换行符

    IE ...--stat...format:'...%n'...

  • 只要不使用换行符或只使用空行,您就可以将 git 图放在每一列 format:'...%n'

    对于非空换行符...%n%CommitPlaceholder...,只有当每行的所有第 n 列都存在并使用相同的宽度时,您才可以将 git 图放在每列 n+1 处

  • 您为特定日志别名定义的树列号的名称必须是 YourLogAlias-col

与普通的 git log 输出相比,这个输出很慢但很好。

现在将改进的代码段添加到您的 .gitconfig

[color "decorate"]
    HEAD   = bold blink italic 196
    branch = 214
    tag    = bold 222

[alias]

    # Delimiter used in every mylog alias as column seperator
    delim     = ^

    # Short overview about the last hashes without graph
    mylog     = log --all --decorate=short --color --pretty=format:'^%C(dim white)%>(12,trunc)%cr%C(reset)^%C(bold 214)%<(7,trunc)%h%C(reset)' -5

    # Log with hashes besides graph tree
    mylog2    = log --all --graph --decorate=short --color --pretty=format:'%C(bold 214)%<(7,trunc)%h%C(reset)^%C(dim white)%>(12,trunc)%cr%C(reset)^%C(auto)%>(15,trunc)%D%C(reset)^%C(white)%<(80,trunc)%s%C(reset)'
    mylog2-col= 3

    # Log with hashes in an own column and more time data
    mylog3    = log --all --graph --decorate=short --color --pretty=format:'^%C(dim white)%>(12,trunc)%cr%C(reset)^%C(cyan)%<(10,trunc)%cs%C(reset)^%C(bold 214)%<(7,trunc)%h%C(reset)^%C(auto)%<(15,trunc)%D%C(reset)^%C(white)%s%C(reset)'
    mylog3-col= 4

    tably     = !bash -c '" \
                \
                \
                declare -A col_length; \
                apost=$(echo -e \"\\u0027\"); \
                delim=$(git config alias.delim); \
                git_log_cmd=$(git config alias.$1); \
                git_tre_col=${2:-$(git config alias.$1-col)}; \
                [[ -z "$git_tre_col" ]] && git_tre_col=1; \
                [[ -z "$git_log_cmd" ]] && { git $1;exit; }; \
                \
                \
                i=0; \
                n=0; \
                while IFS= read -r line;do \
                  ((n++)); \
                  while read -d\"$delim\" -r col_info;do \
                    ((i++)); \
                    [[ -z \"$col_info\" ]] && col_length[\"$n:$i\"]=${col_length[\"${last[$i]:-1}:$i\"]} && ((i--)) && continue; \
                    [[ $i -gt ${i_max:-0} ]] && i_max=$i; \
                    col_length[\"$n:$i\"]=$(grep -Eo \"\\([0-9]*,[lm]*trunc\\)\" <<< \"$col_info\" | grep -Eo \"[0-9]*\" | head -n 1); \
                    [[ -n \"${col_length[\"$n:$i\"]}\" ]] && last[$i]=$n; \
                    chars_extra=$(grep -Eo \"trunc\\).*\" <<< \"$col_info\"); \
                    chars_extra=${chars_extra#trunc)}; \
                    chars_begin=${chars_extra%%\\%*}; \
                    chars_extra=${chars_extra%$apost*}; \
                    chars_extra=${chars_extra#*\\%}; \
                    case \" ad aD ae aE ai aI al aL an aN ar as at b B cd cD ce cE ci cI cl cL cn cN cr \
                            cs ct d D e f G? gd gD ge gE GF GG GK gn gN GP gs GS GT h H N p P s S t T \" in \
                      *\" ${chars_extra:0:2} \"*) \
                        chars_extra=${chars_extra:2}; \
                        chars_after=${chars_extra%%\\%*}; \
                        ;; \
                      *\" ${chars_extra:0:1} \"*) \
                        chars_extra=${chars_extra:1}; \
                        chars_after=${chars_extra%%\\%*}; \
                        ;; \
                      *) \
                        echo \"No Placeholder found. Probably no tablelike output.\"; \
                        continue; \
                        ;; \
                    esac; \
                    if [[ -n \"$chars_begin$chars_after\" ]];then \
                      len_extra=$(echo \"$chars_begin$chars_after\" | wc -m); \
                      col_length["$n:$i"]=$((${col_length["$n:$i"]}+$len_extra-1)); \
                    fi; \
                  done <<< \"${line#*=format:}$delim\"; \
                  i=1; \
                done <<< \"$(echo -e \"${git_log_cmd//\\%n/\\\\n}\")\"; \
                \
                \
                git_log_fst_part=\"${git_log_cmd%%\"$apost\"*}\"; \
                git_log_lst_part=\"${git_log_cmd##*\"$apost\"}\"; \
                git_log_tre_part=\"${git_log_cmd%%\"$delim\"*}\"; \
                git_log_tre_part=\"${git_log_tre_part##*\"$apost\"}\"; \
                git_log_cmd_count=\"$git_log_fst_part$apost $git_log_tre_part$apost$git_log_lst_part\"; \
                col_length[\"1:1\"]=$(eval git \"${git_log_cmd_count// --color}\" | wc -L); \
                \
                \
                i=0; \
                while IFS=\"$delim\" read -r graph rest;do \
                  ((i++)); \
                  graph_line[$i]=\"$graph\"; \
                done < <(eval git \"${git_log_cmd/ --color}\" && echo); \
                \
                \
                i=0; \
                l=0; \
                while IFS= read -r line;do \
                  c=0; \
                  ((i++)); \
                  ((l++)); \
                  [[ $l -gt $n ]] && l=1; \
                  while IFS= read -d\"$delim\" -r col_content;do \
                    ((c++)); \
                    [[ $c -le $git_tre_col ]] && c_corr=-1 || c_corr=0; \
                    if [[ $c -eq 1 ]];then \
                      [[ \"${col_content/\\*}\" = \"$col_content\" ]] && [[ $l -eq 1 ]] && l=$n; \
                      count=$(wc -L <<< \"${graph_line[$i]}\"); \
                      whitespaces=$(seq -s\" \" $((${col_length[\"1:1\"]}-$count))|tr -d \"[:digit:]\"); \
                      col_content[$git_tre_col]=\"${col_content}$whitespaces\"; \
                    else \
                      col_content[$c+$c_corr]=\"$(printf \"%-${col_length[\"$l:$c\"]}s\" \"${col_content:-\"\"}\")\"; \
                    fi; \
                  done <<< \"$line$delim\"; \
                  for ((k=$c+1;k<=$i_max;k++));do \
                    [[ $k -le $git_tre_col ]] && c_corr=-1 || c_corr=0; \
                    col_content[$k+$c_corr]=\"$(printf \"%-${col_length[\"$l:$k\"]:-${col_length[\"${last[$k]:-1}:$k\"]:-0}}s\" \"\")\"; \
                  done; \
                  unset col_content[0]; \
                  echo -e \"${col_content[*]}\"; \
                  unset col_content[*]; \
                done < <(eval git \"$git_log_cmd\" && echo); \
                "' "git-tably"
Run Code Online (Sandbox Code Playgroud)

表中的哪里

  • 第一段将 delim(iter)、YourLogAlias 和 YourLogAlias-col 加载到 shell 变量中
  • 第二个读出每列的长度
  • 第三个计数最大值。树的长度
  • 第四个将树加载到数组中
  • 第五个组织并打印类似表格的输出

结果:


小智 32

有关更详细的文本输出,请尝试:

git log --graph --date-order -C -M --pretty=format:"<%h> %ad [%an] %Cgreen%d%Creset %s" --all --date=short
Run Code Online (Sandbox Code Playgroud)

您可以在$ HOME/.gitconfig中编写别名

[alias]
    graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short
Run Code Online (Sandbox Code Playgroud)


sae*_*gnu 28

gitg:一个基于gtk的存储库查看器,这是一个新的但有趣且有用的
http://git.gnome.org/browse/gitg
我目前使用它

  • 它似乎是"GitX"的一个克隆,并且是一个非常好的.推荐 (2认同)

alb*_*fan 28

虽然有时我使用gitg,但总是回到命令行:

[alias]
    #quick look at all repo
    loggsa = log --color --date-order --graph --oneline --decorate --simplify-by-decoration --all
    #quick look at active branch (or refs pointed)
    loggs  = log --color --date-order --graph --oneline --decorate --simplify-by-decoration
    #extend look at all repo
    logga  = log --color --date-order --graph --oneline --decorate --all
    #extend look at active branch
    logg   = log --color --date-order --graph --oneline --decorate
    #Look with date
    logda  = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\" --all
    logd   = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\"        
    #Look with relative date
    logdra = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\" --all
    logdr = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\"  

    loga   = log --graph --color --decorate --all

    # For repos without subject body commits (vim repo, git-svn clones)
    logt  = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\"
    logta  = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all        
    logtsa = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all --simplify-by-decoration 
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,几乎是按键保存别名,基于:

  • - 颜色:清晰的外观
  • --graph:想象父母
  • - 日期顺序:最容易理解的回购
  • --decorate:谁是谁
  • --onon:很多时候你需要了解一个提交
  • - 简化装饰:基本的第一眼(只是标签,相关的合并,分支)
  • --all:使用和不带此选项的所有别名保存击键
  • --date = relative(%ar):了解repo中的活动(有时一个分支很少在master附近提交但几个月前从他那里提交)

在最近版本的git(1.8.5及更高版本)中,您可以从装饰占位符%d中的%C(自动)中受益

从这里你需要的是一个很好的理解gitrevisions来过滤你需要的东西(像master..develop,其中--simplify-merges可以帮助长期分支)

命令行背后的功能是根据您的需求快速配置(了解repo不是唯一的密钥日志配置,因此有时需要添加--numstat,或--raw或--name-status.这里是git log和别名是快速,强大和(随着时间)你可以实现的最漂亮的图形.甚至更多,默认情况下通过寻呼机显示输出(比如说更少),你总是可以在结果中快速搜索.不相信?你总是可以解析结果像gitgraph这样的项目


drz*_*ala 28

这是我对此事的看法:

截图:

截图

用法:

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

git hist --all - 显示所有分支(包括遥控器)的图表

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

git hist --branches - 显示所有当地分支机构

添加--topo-order到拓扑排序提交,而不是按日期(此别名中的默认值)

优点:

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

建立:

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)'"
Run Code Online (Sandbox Code Playgroud)


Pet*_*tai 17

稍微调整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"
Run Code Online (Sandbox Code Playgroud)

离开--all你现在可以做到

git lgBranch1 <branch name>
Run Code Online (Sandbox Code Playgroud)

甚至

git lgBranch1 --all
Run Code Online (Sandbox Code Playgroud)


Eug*_*ash 14

我有这个git log别名~/.gitconfig来查看图表历史记录:

[alias]
l = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
Run Code Online (Sandbox Code Playgroud)

有了这个,git l将输出如下:

在此输入图像描述

在Git 2.12 +中,您甚至可以使用log.graphColors配置选项自定义图形的线条颜色.

至于日志的格式,它--oneline与添加作者姓名(尊重.mailmap)和相对作者日期类似.请注意,%C(auto)Git> = 1.8.3支持语法,该语法告诉Git使用提交哈希的默认颜色等.

  • **`git log --graph --oneline`** 只是为了确保 oneliner 不会丢失 (2认同)

nod*_*ejh 13

我建议使用tig https://github.com/jonas/tig ,这是一个更好的git命令行工具.

您可以使用自制软件在macOS上安装tig:

$ brew install tig
$ tig
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


kau*_*nav 13

Visual Studio Code 有一个惊人的扩展,Git Graph

Git 图

  • 哦,它叫“Git Graph”,我总是把它与“Git Lens”混淆。 (4认同)

Adr*_*iuk 12

你有没有尝试gitk还是gitk --all?但它没有打印/保存img作为功能.

  • gitk很有效但不是很漂亮. (3认同)

小智 12

GitGraph

生成Git存储库的提交历史记录的PNG或SVG表示.

https://code.google.com/p/gitgraph


And*_*ndy 11

git -c core.pager='less -SRF' log --oneline --graph --decorate
Run Code Online (Sandbox Code Playgroud)

这是我的终端变体,类似于这里的许多答案.我喜欢调整传递给的标志less以防止自动换行.

示例输出

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


one*_*ion 10

贝壳的更像树枝的彩色版本。

电子

其他一些答案显示了由外部工具很好地着色的图树,部分带有彩色线条信息。这是我的 shell 方法,它与我在这里的第一个答案相结合,用于类似表格的输出 ( /sf/answers/4304093671/ )。

特征:

  • 您可以定义所有树的颜色
  • 您可以将每一列染成相应的分支颜色
  • 您可以将树列放置在不同的位置
  • 您可以使用各种git log别名
  • 您可以为每个别名定义一个树列号
  • 你可以把它输送到less -r巨大的历史中

你如何使用它:

定义您的git log别名,如所示的几个答案,例如,来自Slipp D. , albfan , kaoru,使用下面提到的格式说明,并将其与代码片段一起粘贴到您的.gitconfig文件中。从您的项目路径调用它,通常使用

git colored YourLogAlias 或与

git colored YourLogAlias TreeColumnNumber 即时放置树列。

格式化说明:

您的git log别名必须遵循以下格式规则:

  • 使用唯一字符作为每个提交占位符的列分隔符,即^
    ...format:'%h%cr%s'-->
    ...format:'^%h^%cr^%s'
  • 用一种颜色为整列着色或留空以采用各自的分支颜色
    ...format:'^%h^%cr^%s'-->
    ...format:'^%h^%cr^%C(white)%s%C(reset)'(分支颜色中的哈希和时间)
  • 您必须使用%><(<N>[,ltrunc|mtrunc|trunc])trunc 选项之一指定任何列的宽度,但可以在没有它的情况下使用一行上的任何最后提交占位符
    ...format:'^%h^%cr^%C(white)%s%C(reset)'-->
    ...format:'^%<(7,trunc)%h^%<(12,trunc)%cr^%C(white)%<(50,trunc)%s%C(reset)'
  • 如果您需要额外的装饰字符,请将它们直接放在提交占位符周围,即Commit:
    ...^%C(white)%<(50,trunc)%s%C(reset)...-->
    ...^%C(white)%<(50,trunc)Commit:%s%C(reset)...
  • 如果您使用换行符,%n请将它们放在列分隔符之前或末尾
    ...^%C(white)%<(50,trunc)Commit:%s%C(reset)'-->
    ...%n^%C(white)%<(50,trunc)Commit:%s%C(reset)%n'
  • 如果您使用%C(white)上述列颜色,则需要添加--color选项
    ...format:'^%<(7,trunc)%h...-->
    ...--color...format:'^%<(7,trunc)%h...
  • 如果您使用该--stat选项或类似选项,请%n在末尾添加一个换行符
    ...--stat...format:'...'-->
    ...--stat...format:'...%n'

各种各样的:

  • 对于git log具有非空换行符的别名,...%n%CommitPlaceholder...仅当每行的所有第 n 列都存在并使用相同的宽度时,您才可以将 Git 图放置在每列 n+1 处

  • YourLogAlias-col必须是名字,如果你定义在文件中的TreeColumnNumber的.gitconfigYourLogAlias

  • 与正常git log输出相比,这个很慢,但很好

例子:

git colored lgc1 电子

git colored lgc2 电子

git colored lgc3 电子

git colored lgc4 电子

代码片段:

将以下行添加到您的.gitconfig文件中

[alias]

# Define your unique column separator
delim      = ^

# Define your 'git log' aliases and optional tree column numbers
lgc1       = log --all --graph --color --pretty=format:'^%<(7,trunc)%h^%C(white)%<(15,trunc)- %ar -%C(reset)^%<(35,trunc)%s^%C(white)%an%C(reset)'

lgc2       = log --all --graph --color --pretty=format:'%D^%<(7,trunc)%h^%<(35,trunc)%s^%C(white)%<(20,trunc)%an%C(reset)^%C(white) (%ar)%C(reset)'
lgc2-col   = 2

lgc3       = log --all --graph --color --pretty=format:'%<(7,trunc)%h%d^%<(11,trunc)%cs%C(reset)^%s%n^%C(white)%<(11,trunc)%cr%C(reset)^%C(white)%<(25,trunc)From %an%C(reset)^%C(white)%ae%C(reset)%n'
lgc3-col   = 2

lgc4       = log --all --graph --color --pretty=format:'%h^%C(white)%<(25,trunc)%an%C(reset)^%C(white)%<(31,trunc)%aD%C(reset)^%s%n^%C(dim white)%<(25,trunc)%ae%C(reset)^%>(31,trunc)%D%C(reset)%n'
lgc4-col   = 3

# Define your whitespace seperated tree color list
color-list = "1;38;5;222 1;38;5;69 1;38;5;250 1;38;5;70 1;31 1;38;5;93 1;33 2;38;5;11 1;38;5;48 1;35 1;32 1;38;5;111 1;38;5;160 1;38;5;130 1;36 38;5;21"
Run Code Online (Sandbox Code Playgroud)

也将 Bash 片段添加到您的.gitconfig文件中

# This is the Bash snippet which does all the magic
colored = !bash -c '" \
  \
  \
  declare -A col_length col_colored; \
  apost=$(echo -e \"\\u0027\"); \
  delim=$(git config alias.delim); \
  git_log_cmd=$(git config alias.$1); \
  graph_col=${2:-$(git config alias.$1-col)}; \
  color_list=( $(git config alias.color-list) ); \
  [[ -z \"$graph_col\" ]] && graph_col=1; \
  [[ -z \"$git_log_cmd\" ]] && { git $1;exit; }; \
  \
  \
  i=0; \
  n=0; \
  while IFS= read -r line; do \
    ((n++)); \
    while read -d\"$delim\" -r col_info;do \
      ((i++)); \
      [[ -z \"$col_info\" ]] && col_length[\"$n:$i\"]=${col_length[\"${last[$i]:-1}:$i\"]} && ((i--)) && continue; \
      [[ $i -gt ${i_max:-0} ]] && i_max=$i; \
      [[ \"${col_info:1:1}\" = \"C\" ]] && col_colored[\"$n:$i\"]=1; \
      col_length[\"$n:$i\"]=$(grep -Eo \"\\([0-9]*,[lm]*trunc\\)\" <<< \"$col_info\" | grep -Eo \"[0-9]*\" | head -n 1); \
      [[ -n \"${col_length[\"$n:$i\"]}\" ]] && last[$i]=$n; \
      chars_extra=$(grep -Eo \"\\trunc\\).*\" <<< \"$col_info\"); \
      chars_extra=${chars_extra#trunc)}; \
      chars_begin=${chars_extra%%\\%*}; \
      chars_extra=${chars_extra%$apost*}; \
      chars_extra=${chars_extra#*\\%}; \
      case \" ad aD ae aE ai aI al aL an aN ar as at b B cd cD ce cE ci cI cl cL cn cN cr \
              cs ct d D e f G? gd gD ge gE GF GG GK gn gN GP gs GS GT h H N p P s S t T \" in \
        *\" ${chars_extra:0:2} \"*) \
          chars_extra=${chars_extra:2}; \
          chars_after=${chars_extra%%\\%*}; \
          ;; \
        *\" ${chars_extra:0:1} \"*) \
          chars_extra=${chars_extra:1}; \
          chars_after=${chars_extra%%\\%*}; \
          ;; \
        *) \
          echo \"No Placeholder found. Probably no table-like output.\"; \
          continue; \
          ;; \
      esac; \
      if [[ -n \"$chars_begin$chars_after\" ]];then \
        len_extra=$(echo \"$chars_begin$chars_after\" | wc -m); \
        col_length[\"$n:$i\"]=$((${col_length[\"$n:$i\"]}+$len_extra-1)); \
      fi; \
    done <<< \"${line#*=format:}$delim\"; \
    i=1; \
  done <<< \"$(echo -e \"${git_log_cmd//\\%n/\\\\n}\")\"; \
  \
  \
  git_log_fst_part=\"${git_log_cmd%%\"$apost\"*}\"; \
  git_log_lst_part=\"${git_log_cmd##*\"$apost\"}\"; \
  git_log_tre_part=\"${git_log_cmd%%\"$delim\"*}\"; \
  git_log_tre_part=\"${git_log_tre_part##*\"$apost\"}\"; \
  git_log_cmd_count=\"$git_log_fst_part$apost $git_log_tre_part$apost$git_log_lst_part\"; \
  col_length[\"1:1\"]=$(eval git \"${git_log_cmd_count// --color}\" | wc -L); \
  \
  \
  i=0; \
  while IFS=\"$delim\" read -r graph rest;do \
    ((i++)); \
    graph_line[$i]=\"$graph\"; \
  done < <(eval git \"${git_log_cmd/ --color}\" && echo); \
  \
  \
  i=0; \
  l=0; \
  msg_err=; \
  color_list_ind=-1; \
  color_list_num=${#color_list[*]}; \
  color_repeat_ind=1; \
  if [[ $color_list_num -eq 0 ]];then \
    echo \"No tree colors specified via color-list under section [alias] in your .gitconfig\"; \
    echo \"Therefore collecting available Git colors, which may take a while ...\"; \
    while read -d\"[\" -r char;do \
      color=$(sed -nl99 \"l\" <<< \"$char\"); \
      case \"$color\" in \
        *\"m\"*) \
          color=${color%%m*}; \
          ;; \
        *) \
          continue; \
          ;; \
      esac; \
      case \" $color_list \" in \
        *\" $color \"*) \
          continue; \
          ;; \
        *) \
          color_list=\"$color_list$color \"; \
          ;; \
      esac; \
    done <<< \"$(git log --all --color --graph --pretty=format:)\"; \
    echo -e \"Temporary used color-list = \\\"${color_list% }\\\"\\n\"; \
    color_list=( ${color_list% } ); \
    color_list_num=${#color_list[*]}; \
  fi; \
  while IFS= read -r line;do \
    ((i++)); \
    j=-1; \
    case_off=; \
    graph_colored=; \
    graph_line_last=\"${graph_line[$i-1]}\"; \
    graph_line=\"${graph_line[$i]}\"; \
    graph_line_next=\"${graph_line[$i+1]}\"; \
    while IFS= read -r char;do \
      ((j++)); \
      case \"$case_off$char\" in \
        [^\\ \\_\\*\\/\\|\\\\]|\"case_off\"*) \
          graph_colored=\"${graph_colored}\\033[${point_color}m$char\\033[0m\"; \
          case_off=\"case_off\"; \
          ;; \
        \" \") \
          graph_colored=\"${graph_colored}$char\"; \
          case \"$char_last\" in \
            \" \") \
              unset color_ind[$j]; \
              ;; \
          esac; \
          ;; \
        \"*\") \
          case \"${graph_line_last:$j:1}\" in \
            \"*\") \
              :; \
              ;; \
            \"|\") \
              case \"${graph_line_last:$(($j-1)):1}\" in \
                \"\\\\\") \
                  color_ind[$j]=${color_ind_last[$j-1]:-${color_ind[$j-1]}}; \
                  ;; \
                *) \
                  :; \
                  ;; \
              esac; \
              ;; \
            \" \") \
              case \"${graph_line_last:$(($j-1)):1}\" in \
                \"\\\\\") \
                  color_ind[$j]=${color_ind_last[$j-1]:-${color_ind[$j-1]}}; \
                  ;; \
                \"/\") \
                  case \"${graph_line_last:$(($j+1)):1}\" in \
                    \"/\") \
                      color_ind[$j]=${color_ind[$j+1]}; \
                      ;; \
                    \" \") \
                      new_col_ind=${#color[*]}; \
                      while true;do \
                        ((color_list_ind++)); \
                        [[ $color_list_ind -ge $color_list_num ]] && color_list_ind=$color_repeat_ind; \
                        [[ $color_list_ind -ge $color_list_num ]] && break; \
                        new_color=${color_list[$color_list_ind]}; \
                        case \"$new_color\" in \
                          \"\"|[\\ ]*) \
                            continue; \
                            ;; \
                          \"${color[${color_ind[$j-1]}]}\") \
                            [[ $(($color_list_num-$color_repeat_ind)) -gt 1 ]] && continue; \
                            ;;& \
                          *) \
                            color[$new_col_ind]=$new_color; \
                            color_ind[$j]=$new_col_ind; \
                            last_new_colored_line=$i; \
                            break; \
                            ;; \
                        esac 2>/dev/null; \
                      done; \
                      ;; \
                    *) \
                      [[ -n \"$msg_err\" ]] && echo -e \"Unknown case in graph_line $i: $graph_line for char $char at position $j\nwith the former graph_line $(($i-1)): $graph_line_last\"; \
                      ;; \
                  esac; \
                  ;; \
                \" \") \
                  case \"${graph_line_last:$(($j+1)):1}\" in \
                    \"/\") \
                      color_ind[$j]=${color_ind[$j+1]}; \
                      ;; \
                    *) \
                      new_col_ind=${#color[*]}; \
                      while true;do \
                        ((color_list_ind++)); \
                        [[ $color_list_ind -ge $color_list_num ]] && color_list_ind=$color_repeat_ind; \
                        [[ $color_list_ind -ge $color_list_num ]] && break; \
                        new_color=${color_list[$color_list_ind]}; \
                        case \"$new_color\" in \
                          \"\"|[\\ ]*) \
                            continue; \
                            ;; \
                          \"${color[${color_ind[$j-1]}]}\") \
                            [[ $(($color_list_num-$color_repeat_ind)) -gt 1 ]] && continue; \
                            ;;& \
                          *) \
                            color[$new_col_ind]=$new_color; \
                            color_ind[$j]=$new_col_ind; \
                            last_new_colored_line=$i; \
                            break; \
                            ;; \
                        esac 2>/dev/null; \
                      done; \
                      ;; \
                  esac; \
                  ;; \
                *) \
                  [[ -n \"$msg_err\" ]] && echo -e \"Unknown case in graph_line $i: $graph_line for char $char at position $j\nwith the former graph_line $(($i-1)): $graph_line_last\"; \
                  ;; \
              esac; \
              ;; \
            \"\"|[^\\ \\_\\*\\/\\|\\\\]) \
              new_col_ind=${#color[*]}; \
              while true;do \
                ((color_list_ind++)); \
                [[ $color_list_ind -ge $color_list_num ]] && color_list_ind=$color_repeat_ind; \
                [[ $color_list_ind -ge $color_list_num ]] && break; \
                new_color=${color_list[$color_list_ind]}; \
                case \"$new_color\" in \
                  \"\"|[\\ ]*) \
                    continue; \
                    ;; \
                  \"${color[${color_ind[$j-1]}]}\") \
                    [[ $(($color_list_num-$color_repeat_ind)) -gt 1 ]] && continue; \
                    ;;& \
                  *) \
                    color[$new_col_ind]=$new_color; \
                    color_ind[$j]=$new_col_ind; \
                    last_new_colored_line=$i; \
                    break; \
                    ;; \
                esac 2>/dev/null; \
              done; \
              ;; \
            *) \
              [[ -n \"$msg_err\" ]] && echo -e \"Unknown case in graph_line $i: $graph_line for char $char at position $j\nwith the former graph_line $(($i-1)): $graph_line_last\"; \
              ;; \
          esac; \
          graph_colored=\"${graph_colored}\\033[${color[${color_ind[$j]}]}m$char\\033[0m\"; \
          point_color=${color[${color_ind[$j]}]}; \
          ;; \
        \"|\") \
          case \"${graph_line_last:$j:1}\" in \
            \" \") \
              case \"${graph_line_last:$(($j-1)):1}\" in \
                \"/\") \
                  color_ind[$j]=${color_ind[$j+1]}; \
                  ;; \
                \"\\\\\") \
                  color_ind[$j]=${color_ind_last[$j-1]:-${color_ind[$j-1]}}; \
                  ;; \
                *) \
                  case \"${graph_line_last:$(($j+1)):1}\" in \
                    \"/\") \
                      color_ind[$j]=${color_ind[$j+1]}; \
                      ;; \
                    *) \
                      [[ -n \"$msg_err\" ]] && echo -e \"Unknown case in graph_line $i: $graph_line for char $char at position $j\nwith the former graph_line $(($i-1)): $graph_line_last\"; \
                      ;; \
                  esac; \
                  ;; \
              esac; \
              ;; \
            \"|\") \
              case \"${graph_line_last:$(($j-1)):1}\" in \
                \"\\\\\") \
                  case \"${graph_line:$(($j+1)):1}\" in \
                    \"\\\\\") \
                       :; \
                       ;; \
                    \" \") \
                      color_ind[$j]=${color_ind_last[$j-1]}; \
                      ;; \
                    *) \
                      [[ -n \"$msg_err\" ]] && echo -e \"Unknown case in graph_line $i: $graph_line for char $char at position $j\nwith the former graph_line $(($i-1)): $graph_line_last\"; \
                      ;; \
                  esac; \
                  ;; \
                *) \
                  :; \
                  ;; \
              esac; \
              ;; \
            \"*\") \
              case \"${graph_line:$(($j-1)):1}\" in \
                \"/\") \
                  if [[ $last_new_colored_line -eq $(($i-1)) ]];then \
                    new_col_ind=${#color[*]}; \
                    while true;do \
                      ((color_list_ind++)); \
                      [[ $color_list_ind -ge $color_list_num ]] && color_list_ind=$color_repeat_ind; \
                      [[ $color_list_ind -ge $color_list_num ]] && break; \
                      new_color=${color_list[$color_list_ind]}; \
                      case \"$new_color\" in \
                        \"\"|[\\ ]*) \
                          continue; \
                          ;; \
                        \"${color[${color_ind[$j-1]}]}\") \
                          [[ $(($color_list_num-$color_repeat_ind)) -gt 1 ]] && continue; \
                          ;;& \
                        *) \
                          color[$new_col_ind]=$new_color; \
                          color_ind[$j]=$new_col_ind; \
                          break; \
                          ;; \
                      esac 2>/dev/null; \
                    done; \
                  else \
                    color_ind[$j]=${color_ind_last[$j]}; \
                  fi; \
                  ;; \
                *) \
                  :; \
                  ;; \
              esac; \
              ;; \
            \"/\") \
              color_ind[$j]=${color_ind[$j]}; \
              ;; \
            *) \
              [[ -n \"$msg_err\" ]] && echo -e \"Unknown case in graph_line $i: $graph_line for char $char at position $j\nwith the former graph_line $(($i-1)): $graph_line_last\"; \
              ;; \
          esac; \
          graph_colored=\"${graph_colored}\\033[${color[${color_ind[$j]}]}m$char\\033[0m\"; \
          ;; \
        \"/\") \
          case \"${graph_line_last:$(($j)):1}\" in \
            \"|\") \
              case \"${graph_line_last:$(($j+1)):1}\" in \
                \"/\") \
                  case \"${graph_line_next:$j:1}\" in \
                    \"|\") \
                      color_ind[$j]=${color_ind[$j+1]}; \
                      ;; \
                    \" \") \
                      color_ind[$j]=${color_ind[$j]}; \
                      ;; \
                    *) \
                      [[ -n \"$msg_err\" ]] && echo -e \"Unknown case in graph_line $i: $graph_line for char $char at position $j\nwith the former graph_line $(($i-1)): $graph_line_last\"; \
                      ;; \
                  esac; \
                  ;; \
                *) \
                  color_ind[$j]=${color_ind[$j]}; \
                  ;; \
              esac; \
              ;; \
            *) \
              case \"${graph_line_last:$(($j+2)):1}\" in \
                \"/\"|\"_\") \
                  color_ind[$j]=${color_ind[$j+2]}; \
                  ;; \
                *) \
                  case \"${graph_line_last:$(($j+1)):1}\" in \
                    \"/\"|\"_\"|\"|\") \
                      color_ind[$j]=${color_ind[$j+1]}; \
                      ;; \
                    \"*\") \
                      case \"${graph_line:$(($j+1)):1}\" in \
                        \"|\") \
                          if [[ $last_new_colored_line -eq $(($i-1)) ]];then \
                            color_ind[$j]=${color_ind_last[$j+1]}; \
                          else \
   


Ale*_*shi 8

这是我的社区别名:git ls。您git ls可以查看图表,每次提交仅覆盖一行。一切都彩色并带有有用的信息。您还可以检查其他分支上的提交历史记录:

git config --global alias.ls '!f() { git log $1 --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%ae,%ar]" --decorate --graph; }; f'
Run Code Online (Sandbox Code Playgroud)

用法:

# shows commits graph on the current branch
git ls

# shows commits graph on the develop branch
git ls develop 
Run Code Online (Sandbox Code Playgroud)

这是图形视图: 在此输入图像描述


fra*_*acz 7

试试迪塔.它可以将任何ASCII图转换为图像.尽管不是考虑到Git分支而设计的,但我对结果印象深刻.

来源(txt文件):

        +--------+
        | hotfix |
        +---+----+
            |
--*<---*<---*
       ^ 
       |
       \--*<---*
               |
           +---+----+
           | master |
           +--------+
Run Code Online (Sandbox Code Playgroud)

命令:

java -jar ditaa0_9.jar ascii-graph.txt
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

它还支持背景颜色,虚线,不同形状等.查看示例.

  • 同样,https://casual-effects.com/markdeep/ 对于美化手工排列的 ascii 艺术图表非常强大。 (2认同)

Tho*_*mas 6

我不知道直接工具,但也许您可以破解脚本将数据导出为点格式并使用graphviz进行渲染.


Spu*_*ley 6

作为Raphael Web图形库的演示之一,有一个时髦的Git提交图.

该演示是静态的,但它应该很容易获取代码并将其静态数据替换为实时数据集 - 我认为它只是JIT格式的Git提交数据.

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


bug*_*123 6

如果您的存储库位于Gitlab上,则可以使用其图形表示形式,因为它在浏览器中以SVG形式呈现。

在此处输入图片说明


mar*_*ler 5

对于 OS X 用户,我采用了 @gospes 示例,并针对 gsed (通过Homebrewgnu-sed安装)稍微修改了它并调整了颜色(以使用黑色背景,不确定原始示例如何呈现它的方式)在示例中,因为它在具有黑色背景的终端上指定黑色文本)。

\n
[alias]\n    # tree, vtree, stree support\n    logx = log --all --graph --decorate=short --color --format=format:\'%C(bold blue)%h%C(reset)+%C(bold black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\\n+++       %C(bold black)%an%C(reset)%C(bold black): %s%C(reset)\'\n    tree = log --all --graph --decorate=short --color --format=format:\'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\\n         %C(bold black)[%cr]%C(reset)  %x09%C(bold black)%an: %s %C(reset)\'\n    stree = !bash -c \'" \\\n    while IFS=+ read -r hash time branch message; do \\\n        timelength=$(echo \\"$time\\" | gsed -r \\"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\\"); \\\n        timelength=$(echo \\"16+${#time}-${#timelength}\\" | bc); \\\n        printf \\"%${timelength}s    %s %s %s\\n\\" \\"$time\\" \\"$hash\\" \\"$branch\\" \\"\\"; \\\n    done < <(git logx && echo);"\' | less -r\n    vtree = !bash -c \'" \\\n    while IFS=+ read -r hash time branch message; do \\\n      timelength=$(echo \\"$time\\" | gsed -r \\"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\\"); \\\n      timelength=$(echo \\"16+${#time}-${#timelength}\\" | bc); \\\n      printf \\"%${timelength}s    %s %s %s\\n\\" \\"$time\\" \\"$hash\\" \\"$branch\\" \\"$message\\"; \\\n    done < <(git logx && echo);"\' | less -r\n
Run Code Online (Sandbox Code Playgroud)\n

OS X 的关键是首先安装 GNU sed(它有 -r 选项)。使用 Homebrew 可以最轻松地完成此操作,它不会覆盖系统安装的 sed,而是将 GNU sed 安装为“gsed”。我希望这对 @SlippD.Thompson 有所帮助,他在上面评论了OS\xc2\xa0X 不工作的问题。

\n


shu*_*gry 5

〜/ .oh-my-zsh / plugins / git / git.plugin.zsh中的一些别名

gke='\gitk --all $(git log -g --pretty=%h)'
glg='git log --stat'
glgg='git log --graph'
glgga='git log --graph --decorate --all'
glgm='git log --graph --max-count=10'
glgp='git log --stat -p'
glo='git log --oneline --decorate'
glog='git log --oneline --decorate --graph'
gloga='git log --oneline --decorate --graph --all'
glol='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
glola='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --all'
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

647729 次

最近记录:

6 年,5 月 前