Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git日志表格格式_Git_Bash_Scripting - Fatal编程技术网

Git日志表格格式

Git日志表格格式,git,bash,scripting,Git,Bash,Scripting,我有一个简单的别名来显示最后几次提交: log --pretty=format:'%h %an %s' -10 如何使结果显示在列中,如下图所示: 898e8789 Author1 Commit message here 803e8759 Other Author name Commit message here 在Git 1.8.3及更高版本中,在中提供了对此的本机支持,使用%以下命令将以表格形式打印日志 git log --pretty=format:'%h|

我有一个简单的别名来显示最后几次提交:

log --pretty=format:'%h %an %s' -10
如何使结果显示在列中,如下图所示:

898e8789 Author1             Commit message here
803e8759 Other Author name   Commit message here

在Git 1.8.3及更高版本中,在中提供了对此的本机支持,使用
%以下命令将以表格形式打印日志

git log --pretty=format:'%h|%an|%s' -10 | column -t -s '|'
命令“列化”输出,使用“|”作为字段分隔符,它将找出给定输入的最佳列宽,因此即使您有更多字段,它也可以正常工作

在Linux上,只要不使用颜色,它就可以正常工作,Linux实现不能很好地处理颜色

但在MacOSX中,它将处理颜色,您可以使用任何unicode字符作为字段分隔符。我用∑ 因为我很确定它不会偶然出现在提交文本上
|
是一个错误的选择,因为它可能出现在提交描述中,而且如果您使用
--graph--decoration--all
它将显示为用于绘制图形的符号的一部分,您还可以执行以下操作:

git log --pretty=format:'%h %<(20)%an %s' -10

git log--pretty=format:'%h%为了获得真正的表格格式,您还需要截断长度超过20个字符的用户名:

git log --pretty=format:'%h %<(20,trunc)%an %s' -10


git log--pretty=format:'%w($(`tput cols`-1)),0,29)%h%表格格式的问题是可能会耗尽空间

以下是我个人在要展示的基本内容之间的最佳折衷:

  • 做了什么
  • 什么时候
  • 为了能够通过提交散列来挖掘更多的
    how
因此:

git log--pretty--format='%h%aI%如何添加选项卡?
您需要的是:

%x09
这里有一个例子
git log--pretty=格式:“%C(洋红)%h%C(青色)%C(粗体)%ad%Creset%C(青色)%cr%Creset%x09 |%s%C(绿色)%Creset”--日期=短
我希望相对日期是标签式的,因为它不是一个固定的长度,这样所有的列都排成一行(对于少于一年前的任何列)。我一直想让它排成一行,但这是我在时间用完之前所能做到的(讽刺的是)

希望这有帮助


如果您有针对相关年份案例(不仅仅是灰显年份)改进此答案的建议,也很高兴听到这些建议,如果您知道如何操作,请随意编辑此答案以添加它们。

如果有现成的Unix实用程序可以执行此操作,我很想知道!我能想到的最好的东西是Perl格式的输出,这很痛苦。@Zack:man column是你的朋友。不幸的是,这似乎是一个BSDism。它在util linux包中。这似乎是迄今为止最好的解决方案。你在哪里找到了%1上的文档?它在
git帮助日志
docs中,在PRETTY FORMATS部分下被引用(我使用的是git版本1.8.3.4)。这是最短但最准确的答案。不需要其他任何东西,只需要内置git日志。这是1.8.3中的一个新选项,因此如果您使用1.8.3或更高版本,这绝对是一个更好的解决方案。我已经把这个建议纳入了我的答案中,因为它是最重要的,因为它被接受了,因此更可能是人们来到这里时看到的第一件事。虽然这很有效,但使用@Jesse建议的本地git日志方法是非常重要的neater@SeanBurlington当我在2010年写下这个答案时,这个答案并不存在;添加了对间距占位符的支持(尽管出于某种原因,它似乎是)。既然您已经指出有更好的解决方案可用,我已经将其纳入了我的答案中。我希望
%还有什么方法可以将固定大小应用于图形?还要截断长度超过指定大小的字段吗?我正在尝试为所有内容制作一个带有固定位置的日志,因为这样更容易观察。请注意,对于
每个参考
,您可以使用
%(对齐:宽度=20,位置=左)
在格式中,请参阅@TamaMcGlinn,希望这对
tput cols
部分有所帮助,这对于生成与变量term size匹配的格式非常有用:d我看到的第一个答案是:
git log--pretty=format:“%cr |%s'-10 | column-t-s'.
git ... | awk -F '|' '{ printf "%s %-20s %s\n", $1, $2, $3 }'
git log --pretty=format:'%h|%an|%s' -10 | column -t -s '|'
git log --pretty=format:'%h %<(20)%an %s' -10
git log --pretty=format:'%h %<(20,trunc)%an %s' -10
git log --pretty=format:'%h %<(20,trunc)%an %<(39,trunc)%s' -10
git log --pretty=format:'%w(79, 0, 29)%h %<(20,trunc)%an %s' -10
git log --pretty=format:'%w(`tput cols`, 0, 29)%h %<(20,trunc)%an %s' -10
git log --pretty=format:'%w($((`tput cols`-1)), 0, 29)%h %<(20,trunc)%an %s' -10
  git log --pretty --format='%h %aI %<(15)%an ::: %s'
 git log --pretty --format='%h %cI %<(15)%an ::: %s'