我如何用(至少)这些信息显示git日志输出:

* author
* commit date
* change

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

(try——format=oneline,但不显示日期)


当前回答

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

首先是固定宽度的内容。最不重要的部分——电子邮件域——是最后一个很容易过滤的部分。

其他回答

最后的-10表示最近10次提交。

使用预定义的git别名(hs - history的缩写):

git hs

由命令创建一次:

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

%h =缩写提交哈希 %cd =提交日期(格式尊重——date= option) %aN =作者名(respect .mailmap) %d = ref name %s = subject

附注:从Git v2.13.0开始,——decoration默认启用。

引用:

Git - Git -log文档 Git中作者和提交者的区别? GitHub如何使用Git的作者日期和提交日期

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

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

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

Tig可能是git log命令的替代品,在主要的开源*nix发行版中可用。

在debian或ubuntu上尝试按以下方式安装和运行:

$ sudo apt-get install tig

对于mac用户,brew可以拯救他们:

$ brew 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:蓝色;第二栏:绿色;第3列:默认文本颜色。最后一行,高亮显示。按Q或Q退出。


Tig对没有粗糙边缘的列进行了校正,而ASCII制表符(%x09)并不能保证这一点。

对于短日期格式,请键入大写D(注意:小写D打开diff视图)。通过在~/.tigrc中添加show-date = short来永久配置它;或者在.git/configure或~/.gitconfig的[tig]部分中。

看到整个变化:

回车。一个子窗格将在窗口的下半部分打开。 使用k, j键滚动子窗格中的更改。 同时,使用上、下键从一个提交移动到另一个提交。

由于tig与git是分开的,而且显然是*nix专用的,它可能需要cygwin才能安装在windows上。但是对于fedora,我相信安装命令是$ su,(输入root密码),# yum install tig。对于freebsd尝试% su,(输入root密码),# pkg_add -r tig。


顺便说一下,tig的好处不仅仅是快速查看日志: 截图& 手册

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问题的启发:“git log output like svn ls -v”,我发现我可以添加我需要的确切参数。

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

如果你好奇有哪些不同的选择: %h =缩写提交哈希 %x09 = TAB(代码9的字符) %an =作者名 %ad =作者日期(格式尊重——date= option) %s = subject 来自kernel.org/pub/software/scm/git/docs/git-log.html (PRETTY格式部分)由Vivek的评论。

如果你想指定一个文件或文件夹,只需在最后添加路径:

%ad =作者日期(格式尊重——date=option) ——date=raw显示从epoch (1970-01-01 00:00:00 UTC)开始的秒数,后面是一个空格,然后是时区,作为UTC Reference的偏移量

git log -1 --pretty=format:"%ad" --date=raw path/to/your/folder