Git的日志表格格式 [英] Git log tabular formatting
问题描述
我有一个简单的别名,显示最后几个提交:
登录 - pretty =格式为:%H%的%s'的-10
我怎样才能让要显示在列中的结果,这样的:
898e8789作者1在这里提交信息
803e8759其他作者姓名提交的信息在这里
在Git 1.8.3及以后,有一个在的 pretty格式,使用%≤( N )
语法格式化下一个占位符的 N 的宽列:
$ git的日志 - pretty =格式为:%H%≤(20)%的%s'的-10
有关版本1.8.3之前,这个答案的previous版本,低于保留,应该工作。
下面是一个使用bash中的一种解决方案读
来解析日志行回分开,和的printf
来打印出来,与作者的固定宽度的字段名称,以便列将保持一字排开。它假定 |
绝不会出现在作者的名字;你可以选择另一种分隔符,如果你认为这可能是一个问题。
git的日志 - pretty =格式为:%H |%的|%s'的-10 |
而IFS ='|'阅读哈希作者信息
做
printf的'%S%-20s%S \\ n'$哈希,$作者$消息
DONE
您可以通过创建这个作为一个别名:
[别名]
mylog =git的日志 - pretty =格式:!%H |%的|%s'的-10 |而IFS ='|'阅读哈希笔者消息;做的printf'%S%-20s%S \\ N'\\$哈希\\\\$作者\\\\$消息\\;完成
我敢肯定,你可以用更少的字符做 AWK
但作为的五岳得好,
每当面临着一个问题,有人说让我们用AWK。现在,他们有两个问题。
块引用>当然,话说回来,我必须弄清楚如何做到这一点在
AWK
这是一个有点短:混帐... | awk的-F| '{printf的%s%-20s%S \\ n,$ 1,$ 2,$ 3}
I have a simple alias to display few last commits:
log --pretty=format:'%h %an %s' -10
How can I make the results to be displayed in columns, like this:
898e8789 Author1 Commit message here 803e8759 Other Author name Commit message here
解决方案In Git 1.8.3 and later, there is native support for this in the pretty format, using the
%<(N)
syntax to format the next placeholder as N columns wide:$ git log --pretty=format:'%h %<(20)%an %s' -10
For versions before 1.8.3, the previous version of this answer, retained below, should work.
Here's a solution in Bash using
read
to parse the log lines back apart, andprintf
to print them out, with a fixed width field for the authors name so the columns will stay lined up. It assumes that|
will never appear in the author's name; you can choose another delimiter if you think that might be a problem.git log --pretty=format:'%h|%an|%s' -10 | while IFS='|' read hash author message do printf '%s %-20s %s\n' "$hash" "$author" "$message" done
You can create this as an alias using:
[alias] mylog = "!git log --pretty=format:'%h|%an|%s' -10 | while IFS='|' read hash author message; do printf '%s %-20s %s\n' \"$hash\" \"$author\" \"$message\"; done"
I'm sure you could do this in fewer characters using
awk
but as the saying goes,Whenever faced with a problem, some people say "Lets use AWK." Now, they have two problems.
Of course, having said that, I had to figure out how to do it in
awk
which is a bit shorter:git ... | awk -F '|' '{ printf "%s %-20s %s\n", $1, $2, $3 }'
这篇关于Git的日志表格格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!