包含作者和日期的git日志的最短输出

时间:2009-09-17 19:58:34

标签: git formatting logging

如何使用(至少)此信息显示git日志输出:

* author
* commit date
* change

我希望每个日志条目压缩到一行。什么是最短的格式?

(尝试--format=oneline,但没有显示日期)

15 个答案:

答案 0 :(得分:555)

git log --pretty=format:"%h%x09%an%x09%ad%x09%s"

完成了这项工作。这输出:

  fbc3503 mads    Thu Dec 4 07:43:27 2008 +0000   show mobile if phone is null...   
  ec36490 jesper  Wed Nov 26 05:41:37 2008 +0000  Cleanup after [942]: Using timezon
  ae62afd tobias  Tue Nov 25 21:42:55 2008 +0000  Fixed #67 by adding time zone supp
  164be7e mads    Tue Nov 25 19:56:43 2008 +0000  fixed tests, and a 'unending appoi
  93f1526 jesper  Tue Nov 25 09:45:56 2008 +0000  adding time.ZONE.now as time zone 
  2f0f8c1 tobias  Tue Nov 25 03:07:02 2008 +0000  Timezone configured in environment
  a33c1dc jesper  Tue Nov 25 01:26:18 2008 +0000  updated to most recent will_pagina

受到stackoverflow question: "git log output like svn ls -v"的启发,我发现我可以添加我需要的确切参数。

要缩短日期(不显示时间),请使用--date=short

如果你好奇不同的选择是什么:
%h =缩写提交哈希
%x09 = tab(代码9的字符)
%an =作者姓名
%ad =作者日期(格式尊重 - 日期=选项)
%s =主题
来自kernel.org/pub/software/scm/git/docs/git-log.html(PRETTY FORMATS部分)评论Vivek。

答案 1 :(得分:166)

我使用这两个.gitconfig设置:

[log]
  date = relative
[format]
  pretty = format:%h %Cblue%ad%Creset %ae %Cgreen%s%Creset

%ad是作者日期,可以由--date或.gitconfig中[log]节中指定的选项覆盖。 我喜欢相对的日期,因为它让人立刻感觉到什么东西被投入。 输出如下:

6c3e1a2 2 hours ago you@me.com lsof is a dependency now.
0754f18 11 hours ago you@me.com Properly unmount, so detaching works.
336a3ac 13 hours ago you@me.com Show ami registration command if auto register fails
be2ad45 17 hours ago you@me.com Fixes #6. Sao Paolo region is included as well.
5aed68e 17 hours ago you@me.com Shorten while loops

这当然都是彩色的,因此很容易区分日志行的各个部分。 此外,由于[format]部分,因此在键入git log时是默认设置。

2014年更新: 由于git现在支持填充,我对上面的版本进行了很好的修改:

pretty = format:%C(yellow)%h %Cblue%>(12)%ad %Cgreen%<(7)%aN%Cred%d %Creset%s

这个右对齐相对日期和左对齐提交者名称,这意味着你得到一个容易在眼睛上的列状外观。

截图

ss#1

2016更新:由于GPG提交签名正在成为一件事,我想我会用包含签名验证的版本更新这篇文章(在截图中它是提交后的洋红色字母)。对旗帜的简短解释:

  

%G?:显示好的(有效)签名“G”,坏签名显示“B”,有效期未知的好签名“U”和无签名“N”

其他变化包括:

  • 如果输出是tty以外的其他东西(这对于grepping等很有用),现在会删除颜色。
  • git log -g现在包含reflog选择器。
  • 在refnames上保存2个parens并将它们放在最后(以保持列对齐)
  • 如果篇幅太长(例如3 years, 4..
  • ,则截断相对日期
  • 截断提交者名称(对某些人来说可能有点短暂,只需更改%<(7,trunc)或查看git .mailmap feature以缩短提交者名称)

这是配置:

pretty = format:%C(auto,yellow)%h%C(auto,magenta)% G? %C(auto,blue)%>(12,trunc)%ad %C(auto,green)%<(7,trunc)%aN%C(auto,reset)%s%C(auto,red)% gD% D

现在所有的列对齐现在保留得更好,但牺牲了一些(希望)无用的字符。 如果您有任何改进,请随意编辑,我希望使消息颜色取决于提交是否已签名,但似乎不可能是atm。

截图

Screenshot of git log

答案 2 :(得分:88)

git log --pretty=format:"%H %an %ad"

使用--date=设置日期格式

git log --pretty=format:"%H %an %ad" --date=short

答案 3 :(得分:45)

tig 是使用主要开源* nix发行版上提供的 git log 命令的可能替代方法。

debian或ubuntu 上尝试安装并运行如下:

$ sudo apt-get install tig

(tig安装)

$ tig

(日志在寻呼机中显示如下,当前提交的散列显示在底部)

2010-03-17 01:07 ndesigner      changes to sponsors list
2010-03-17 00:19 rcoder         Raise 404 when an invalid year is specified.
2010-03-17 00:06 rcoder         Sponsors page now shows sponsors' level.
-------------------------- skip some lines ---------------------------------
[main] 531f35e925f53adeb2146dcfc9c6a6ef24e93619 - commit 1 of 32 (100%)

由于markdown不支持文本着色,想象一下:第1列:蓝色;第2栏:绿色;第3列:默认文本颜色。最后一行,突出显示。点击 Q q 退出。


tig证明列没有参差不齐的边,ascii标签(%x09)不保证。

对于短日期格式点击资本 D (注意:小写 d 会打开差异视图。)通过添加{{}来永久配置它1}}到〜/ .tigrc;或者在.git / configure或〜/ .gitconfig中的show-date = short部分。

要查看整个更改

  • 点击输入。子窗格将在窗口的下半部分打开。
  • 使用 k j 键滚动子窗格中的更改。
  • 同时,使用向上向下键从提交转为提交。

由于tig与git分开并且显然是* nix特定的,因此可能需要在windows上安装cygwin。但对于 fedora ,我认为安装命令为[tig]$ su(enter root password)。对于 freebsd ,请尝试# yum install tig% su(enter root password)


顺便说一句,tig比快速查看日志要好很多: Screenshots&amp; Manual

答案 4 :(得分:36)

随意使用这个:

git log --pretty="%C(Yellow)%h  %C(reset)%ad (%C(Green)%cr%C(reset))%x09 %C(Cyan)%an: %C(reset)%s"

查找

enter image description here

答案 5 :(得分:33)

git log --pretty=format:'%h %ad %s (%an)' --date=short  

git log --pretty=format:'%h %ad %s | %an' --date=short  

...对cdunn2001上面的答案进行了重复:我失去了作者的电子邮件,并且只包括作者的名字,如Jesper和knittl,但与cdunn2001保持输出在恒定宽度的列中的想法一致阅读(好主意!)。但是,为了代替作者名称的单独左对齐列,我使用括号将该标志包装在命令的末尾,或者用管道将其偏移。 (可能真的是任何在阅读输出时作为视觉辅助的角色......虽然可能有必要避免使用反斜杠或正斜杠来减少输出与目录或其他东西的混淆。)

示例输出:

6fdd155 2015-08-10 Fixes casting error in doSave | John Doe
c4f4032 2015-08-10 Fix for IE save. Add help button. | Jane
29a24a6 2015-08-10 Fixes bug in Course | Mac

答案 6 :(得分:23)

使用预定义的git别名,即:

$ git work

通过命令创建一次:

$ git config --global alias.work 'log --pretty=format:"%h%x09%an%x09%ad%x09%s"'

https://git-scm.com/book/tr/v2/Git-Basics-Git-Aliases

或者用图表着色更多:

$ git config --global alias.work 'log --pretty=format:"%C(yellow)%h %ar %C(auto)%d %Creset %s , %Cblue%cn" --graph --all'

enter image description here

答案 7 :(得分:21)

enter image description here 注意最后的-10,以仅显示最后10个条目。

使用预定义的git别名(hs-历史记录的缩写):

git hs

由命令创建一次:

git config --global alias.hs "log --pretty='%C(yellow)%h %C(cyan)%ad %Cblue%an%C(auto)%d %Creset%s' --date=relative --date-order --graph"

%h =缩写提交哈希
%ad =作者日期(格式遵循--date =选项,因此您以后可以进行调整
%an =作者姓名
%d =引用名称
%s =主题

参考:https://git-scm.com/docs/git-log#_pretty_formats

答案 8 :(得分:8)

git log --pretty=format:'%h %ad  %s%x09%ae' --date=short

结果:

e17bae5 2011-09-30  Integrate from development -> main      nixon@whitehouse.gov
eaead2c 2011-09-30  More stuff that is not worth mentioning bgates@apple.com
eb6a336 2011-09-22  Merge branch 'freebase' into development        jobs@nirvana.org

首先是恒定宽度的东西。最不重要的部分 - 电子邮件域 - 最后也很容易过滤。

答案 9 :(得分:4)

要显示我已准备推送的提交,我会

git log remotes/trunk~4..HEAD --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" --date=short | awk -F'\t' '{gsub(/[, ]/,"",$2);gsub(/HEAD/, "\033[1;36mH\033[00m",$2);gsub(/master/, "\033[1;32mm\033[00m",$2);gsub(/trunk/, "\033[1;31mt\033[00m",$2);print $1 "\t" gensub(/([\(\)])/, "\033[0;33m\\1\033[00m","g",$2) $3}' | less -eiFRXS

输出类似于:

ef87da7 2013-01-17 haslers      (Hm)Fix NPE in Frobble
8f6d80f 2013-01-17 haslers      Refactor Frobble
815813b 2013-01-17 haslers      (t)Add Wibble to Frobble
3616373 2013-01-17 haslers      Add Foo to Frobble
3b5ccf0 2013-01-17 haslers      Add Bar to Frobble
a1db9ef 2013-01-17 haslers      Add Frobble Widget

第一列显示为黄色,而parentesis中的'H''m'和't'显示HEAD,master和trunk并以其通常的“--decorate”颜色显示

这里有换行符,所以你可以看到它在做什么:

git log remotes/trunk~4..HEAD --date=short
    --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s"
    | awk -F'\t' '{
         gsub(/[, ]/,"",$2);
         gsub(/HEAD/, "\033[1;36mH\033[00m",$2);
         gsub(/master/, "\033[1;32mm\033[00m",$2);
         gsub(/trunk/, "\033[1;31mt\033[00m",$2);
         print $1 "\t" gensub(/([\(\)])/, "\033[0;33m\\1\033[00m","g",$2) $3}'

我已经别名“上演”了:

git config alias.staged '!git log remotes/trunk~4..HEAD --date=short --pretty=format:"%C(yellow)%h%C(white) %ad %aN%x09%d%x09%s" | awk -F"\t" "{gsub(/[, ]/,\"\",\$2);gsub(/HEAD/, \"\033[1;36mH\033[00m\",\$2);gsub(/master/, \"\033[1;32mm\033[00m\",\$2);gsub(/trunk/, \"\033[1;31mt\033[00m\",\$2);print \$1 \"\t\" gensub(/([\(\)])/, \"\033[0;33m\\\\\1\033[00m\",\"g\",\$2) \$3}"'

(有没有一种更简单的方法可以解决这个问题?找出需要逃避的东西有点棘手)

答案 10 :(得分:3)

git --no-pager log --pretty=tformat:"%C(yellow)%h %C(cyan)%ad %Cblue%an%C(auto)%d %Creset%s" --graph --date=format:"%Y-%m-%d %H:%M" -25 

我使用别名

alias gitlog='git --no-pager log --pretty=tformat:"%C(yellow)%h %C(cyan)%ad %Cblue%an%C(auto)%d %Creset%s" --graph --date=format:"%Y-%m-%d %H:%M" -25'

差异:我使用 tformat 和 isodate 没有秒和时区,使用 --no-pager 你会看到颜色

答案 11 :(得分:1)

所有上述建议都使用MyTask task = new MyTask(this, rd.Url, new MyTask(this, rd+1.url, null)占位符作为主题。我建议使用%s,因为%B格式化preserves new lines并且多行提交消息显示为压扁。

%s

答案 12 :(得分:0)

在项目文件夹中运行:

$ git log --pretty=format:"%C(yellow)%h %ar %C(auto)%d %Creset %s , %Cblue%cn" --graph --all

如果您愿意,可以将此行添加到〜/ .gitconfig:

[alias]
    ...
    list = log --pretty=format:\"%C(yellow)%h %ar %C(auto)%d %Creset %s, %Cblue%cn\" --graph --all

答案 13 :(得分:0)

尝试git log --pretty = fuller,它将显示给您:- 作者: 作者日期: 承诺: 提交日期:

希望这会有所帮助。

答案 14 :(得分:0)

如果您想指定文件或文件夹,只需在末尾添加路径:

  • %ad = 作者日期(格式尊重 --date=option)
  • --date=raw 将日期显示为自纪元以来的秒数 (1970-01-01 00:00:00 UTC),后跟一个空格,然后是时区作为与 UTC 的偏移量 Reference< /li>
git log -1 --pretty=format:"%ad" --date=raw path/to/your/folder