我如何用(至少)这些信息显示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

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

其他回答

试试git log——pretty=fuller,它会告诉你:- 作者: 作者日期: 提交: 提交日期:

希望这能有所帮助。

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-page你会看到颜色

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的评论。

为了显示我已经准备好执行的提交

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

其中第一列出现在黄色,'H' 'm'和't'在括号中显示的头部,主人和主干,并出现在他们通常的“装饰”颜色

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

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}'

我用别名“staging”:

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}"'

(有没有更简单的方法来避免这种情况?弄清楚需要逃脱的是什么有点棘手)

看起来这就是你想要的:

git log --pretty=" %C(reset)%ad %C(Cyan)%an: %C(reset)%s"

(个人注意,你应该总是有提交哈希..)