git log

这是Git中最常用的命令,比如输入 git log时,输出以下内容:

commit 5508fde9083465ff2dded7c005cc404bbdebae12

Author: hmx <417688867@qq.com>

Date:   Mon Mar 27 10:18:57 2017 +0800

   add new file

看到日期格式很不爽,那么我们怎么改成熟悉的格式呢,直接上代码。

git config --global alias.logd 'log --pretty=format:"%C(yellow)commit %H %n%CresetAuthor: %an <%ae> %nDate:   %ai %n%n %s %n%n"'

然后输入 git logd,这时控制台打印出以下信息了:

commit 5508fde9083465ff2dded7c005cc404bbdebae12

Author: hmx <417688867@qq.com>

Date:   2017-03-27 10:18:57 +0800

add new file

发现日期变了,变的熟悉了,那么我们解析以上的代码以及参考以下的参数,来更改自己想要的格式。

alias:别名,这里我们起了个别名,输入命令时 git 跟着我们所起的别名就可以了

pretty:使用其他格式显示历史提交信,可选项有:oneline,short,medium,full,fuller,email,raw以及format:<string>,默认为medium,如:

    1. --pretty=oneline:一行显示,只显示哈希值和提交说明(--online本身也可以作为单独的属性)

    2. --pretty=format:” ":控制显示的记录格式,如:

    1. %H  提交对象(commit)的完整哈希字串
    2. %h  提交对象的简短哈希字串
    3. %T  树对象(tree)的完整哈希字串
    4. %t  树对象的简短哈希字串
    5. %P  父对象(parent)的完整哈希字串
    6. %p  父对象的简短哈希字串
    7. %an 作者(author)的名字
    8. %ae 作者的电子邮件地址
    9. %ad 作者修订日期(可以用 -date= 选项定制格式)
    10. %ar 作者修订日期,按多久以前的方式显示
    11. %cn 提交者(committer)的名字
      1. 作者和提交者的区别不知道是啥?
      2. 作者与提交者的关系:作者是程序的修改者,提交者是代码提交人(自己的修改不提交是怎么能让别人拉下来再提交的?)
      3. 其实作者指的是实际作出修改的人,提交者指的是最后将此工作成果提交到仓库的人。所以,当你为某个项目发布补丁,然后某个核心成员将你的补丁并入项目时,你就是作者,而那个核心成员就是提交者(soga)
    12. %ce 提交者的电子邮件地址
    13. %cd 提交日期(可以用 -date= 选项定制格式)
    14. %cr 提交日期,按多久以前的方式显示
    15. %s  提交说明
    16. 带颜色的--pretty=format:” ",这个另外写出来分析
      1. 以这句为例:%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>
      2. 它的效果是:   
      3. 先断句:[%Cred%h][%Creset   -][%C(yellow)%d ][%Cblue%s][%Cgreen(%cd)][%C(bold blue)<%an>]
      4. 然后就是很明显能得到的规律了
        1. 一个颜色+一个内容
        2. 颜色以%C开头,后边接几种颜色,还可以设置字体,如果要设置字体的话,要一块加个括号
          1. 能设置的颜色值包括:reset(默认的灰色),normal, black, red, green, yellow, blue, magenta, cyan, white.
          2. 字体属性则有bold, dim, ul, blink, reverse.  
        3. 内容可以是占位元字符,也可以是直接显示的普通字符
  1. --date= (relative|local|default|iso|rfc|short|raw):定制后边如果出现%ad或%cd时的日期格式
    1. 有几个默认选项
      1. --date=relative:shows dates relative to the current time, e.g. "2 hours ago".
      2. --date=local:shows timestamps in user’s local timezone.
      3. --date=iso (or --date=iso8601):shows timestamps in ISO 8601 format.
      4. --date=rfc (or --date=rfc2822):shows timestamps in RFC 2822 format,often found in E-mail messages.
      5. --date=short:shows only date but not time, in YYYY-MM-DD format.这个挺好用
      6. --date=raw:shows the date in the internal raw git format %s %z format.
      7. --date=default:shows timestamps in the original timezone (either committer’s or author’s).
    2. 也可以自定义格式(需要git版本2.6.0以上),比如--date=format:'%Y-%m-%d %H:%M:%S' 会格式化成:2016-01-13 11:32:13,其他的格式化占位符如下:

 

# 下面参数定义列表
'%H': commit hash
'%h': 缩短的commit hash
'%T': tree hash
'%t': 缩短的 tree hash
'%P': parent hashes
'%p': 缩短的 parent hashes
'%an': 作者名字
'%aN': mailmap的作者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
'%ae': 作者邮箱
'%aE': 作者邮箱 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
'%ad': 日期 (--date= 制定的格式)
'%aD': 日期, RFC2822格式
'%ar': 日期, 相对格式(1 day ago)
'%at': 日期, UNIX timestamp
'%ai': 日期, ISO 8601 格式
'%cn': 提交者名字
'%cN': 提交者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
'%ce': 提交者 email
'%cE': 提交者 email (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
'%cd': 提交日期 (--date= 制定的格式)
'%cD': 提交日期, RFC2822格式
'%cr': 提交日期, 相对格式(1 day ago)
'%ct': 提交日期, UNIX timestamp
'%ci': 提交日期, ISO 8601 格式
'%d': ref名称
'%e': encoding
'%s': commit信息标题
'%f': sanitized subject line, suitable for a filename
'%b': commit信息内容
'%N': commit notes
'%gD': reflog selector, e.g., refs/stash@{1}
'%gd': shortened reflog selector, e.g., stash@{1}
'%gs': reflog subject
'%Cred': 切换到红色
'%Cgreen': 切换到绿色
'%Cblue': 切换到蓝色
'%Creset': 重设颜色
'%C(...)': 制定颜色, as described in color.branch.* config option
'%m': left, right or boundary mark
'%n': 换行
'%%': a raw %
'%x00': print a byte from a hex code
'%w([[,[,]]])': switch line wrapping, like the -w option of git-shortlog(1).

 

posted @ 2017-04-02 17:18  90℃_smile  阅读(187)  评论(0编辑  收藏  举报