Sli*_*son 1770
更新:这个答案得到了比应有的更多的关注.它最初发布是因为我认为图形看起来不错,它们可以在Illustrator中用于出版物 - 并且没有更好的解决方案.但是现在存在更多适用于这个Q的答案,比如fracz 's,Jubobs '或Harry Lee 's!请尽快投票!
更新2:我已经在git问题中向可视化分支拓扑发布了这个答案的改进版本,因为它在那里更合适.该版本包括 lg3,显示作者和提交者信息,所以你真的应该检查出来.留下这个答案的历史(和代表,我会承认)的原因,虽然我真的很想删除它.
2¢:我通常在我的~/.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 lg2看起来是这样的:

Pat*_*パトシ 1046
这里的许多答案都很棒,但对于那些只需要一个简单的一行到点答案而不必设置别名或任何额外内容的人来说,这里是:
git log --all --decorate --oneline --graph
Run Code Online (Sandbox Code Playgroud)
不是每个人都会一直在做git log,但是当你需要它时,请记住:
" 狗 "= GIT中的日志- 一个 LL - d ecorate - ö neline - 克拉夫
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别名.
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)

或者使用metro模板:

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

用JSFiddle测试它.
由@bsara 用Git Grapher生成它.
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)
nop*_*ole 60
SourceTree是一个非常好的.它打印出一个外观漂亮和中等大小的历史记录和分支图:(以下是在一个实验性的Git项目上完成,只是为了看到一些分支).支持Windows 7+和Mac OS X 10.6+.

Har*_*Lee 58
我刚刚编写了一个工具,可以使用HTML/Canvas生成漂亮的git提交图.
并提供一个jQuery插件,使其易于使用.
[github] https://github.com/tclh123/commits-graph
预习:

Tux*_*ude 55
git-forest是一个很好的perl脚本,我已经使用了一年多,我几乎git log不再直接使用命令.
这些是我喜欢这个脚本的一些东西:
--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)
这是终端上输出的样子:
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(该工具)
Mat*_*nry 44
基于我在相关问题的答案中找到的Graphviz脚本,我已经破解了一个ruby脚本,它创建了一个git存储库的摘要视图.它省略了所有线性历史记录,只显示"有趣"提交,即具有多个父项,多个子项或由分支或标记指向的提交.这是为jquery生成的图表的片段:

git-big-picture和BranchMaster是类似的工具,它们只通过显示标签,分支,合并等的相关性来尝试仅显示图形的高级结构.
这个问题还有一些选择.
Dus*_*tin 37
取决于他们的样子.我使用gitx制作这样的照片:

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

gos*_*pes 37
我已经添加了三个自定义命令:git tree,git stree和git 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 stree和git 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)

[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版本1.9a.颜色值'auto'显然是在这个版本中首次亮相.这是一个很好的补充,因为分支名称将获得不同的颜色.这使得更容易区分本地和远程分支.
one*_*ion 36
一个漂亮干净的类似于表格的 shell 的 Git 图形输出
除了图树之外,通常还有散列
或者在一个额外的列中
编辑:您想在不阅读所有解释的情况下立即开始吗?跳转到编辑 6。
信息:对于外壳的更像分支的彩色版本,另见我的第二个答案(/sf/answers/4427719481/)。
到目前为止,在这个问题的所有答案中,没有一个显示外壳的干净的类似表格的输出。最接近的是来自我开始的福音书的这个答案。
我的方法的核心点是只计算向用户显示的树字符。然后用空格将它们填充到个人长度。
除了 Git,你还需要这些工具
主要适用于任何 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 命令的这一部分(颜色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:或者你喜欢你自己的那部分颜色混合,一个带有闪烁头部的花哨输出?
为了能够首先设置头部、分支名称和标签的样式,我们需要像编辑 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 输出
眨眼太多了!只是为了证明什么是可能的。指定颜色太少会导致颜色重复。
编辑 6: 由于您的赞成票,我改进了代码段。现在,您几乎可以使用任何 git log 命令来提供它,而不必再修改代码。尝试一下!
它是如何工作的?
然后就打电话
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)
表中的哪里
结果:
小智 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
我目前使用它
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)
正如您所看到的,几乎是按键保存别名,基于:
在最近版本的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使用提交哈希的默认颜色等.
nod*_*ejh 13
我建议使用tig https://github.com/jonas/tig
,这是一个更好的git命令行工具.
您可以使用自制软件在macOS上安装tig:
$ brew install tig
$ tig
Run Code Online (Sandbox Code Playgroud)
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的.gitconfig为YourLogAlias
与正常git log输出相比,这个很慢,但很好
例子:
代码片段:
将以下行添加到您的.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 \
这是我的社区别名: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)
试试迪塔.它可以将任何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)
结果:
它还支持背景颜色,虚线,不同形状等.查看示例.
作为Raphael Web图形库的演示之一,有一个时髦的Git提交图.
该演示是静态的,但它应该很容易获取代码并将其静态数据替换为实时数据集 - 我认为它只是JIT格式的Git提交数据.
演示在这里:http://dmitrybaranovskiy.github.io/raphael/github/impact.html
如果您的存储库位于Gitlab上,则可以使用其图形表示形式,因为它在浏览器中以SVG形式呈现。
转到存储库的图形视图,例如https://gitlab.com/gitlab-org/gitter/webapp/network/develop
将图表向下滚动到底部(延迟加载提交!)
使用浏览器的检查器将SVG元素复制到新文件
在您选择的渲染器中打开它,例如Inkscape
对于 OS X 用户,我采用了 @gospes 示例,并针对 gsed (通过Homebrewgnu-sed安装)稍微修改了它并调整了颜色(以使用黑色背景,不确定原始示例如何呈现它的方式)在示例中,因为它在具有黑色背景的终端上指定黑色文本)。
[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\nRun Code Online (Sandbox Code Playgroud)\nOS X 的关键是首先安装 GNU sed(它有 -r 选项)。使用 Homebrew 可以最轻松地完成此操作,它不会覆盖系统安装的 sed,而是将 GNU sed 安装为“gsed”。我希望这对 @SlippD.Thompson 有所帮助,他在上面评论了OS\xc2\xa0X 不工作的问题。
\n〜/ .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 次 |
| 最近记录: |