分享

个性化你的Git Log的输出格式,参数集合

 ala咪s 2017-03-03

个性化你的Git Log的输出格式,更容易肉眼查看

时间 2014-10-17 13:29:52  和煦的点滴
主题 Git

如果只想输出bash:

$ git log --pretty=format:"%h" 
cee50d5
bd14bfa
8cfdbf6
de13087
a3beaba
4c41c21
cfe01af
.....

$ git log -- pretty = format : "%h"

cee50d5

bd14bfa

8cfdbf6

de13087

a3beaba

4c41c21

cfe01af

. . . . .

$ git log --pretty=oneline
cee50d5d7621291b86f628cce4465714d7f9d034 add source
bd14bfa9c495ac739cfd7fb0aedc37cebf25a64c add redirect type
8cfdbf631bb9884968b8e2d6a64af72422fe985f add sponsor transfer log
de13087ef51e57925e77f832b81511305bde0df8 change display area name
a3beaba9e3ff7affff7b018fc7d781d7212d4944 rename GoogleAf*.php to Googleaf*.php
4c41c21c16dab60ebc59a4ad869fad0e7e655551 add sponsor click tracking
cfe01afdb4e29c13bf60d2b38d52f82a4be8dfe0 add monitor js by Quanqi provider for tracking JS click.
5fb43a0a0292f0553f2ded35ba94f6896c5c38c2 add awp for filter source and ignore google mediaparenter robots
765de4caf048790f5c9960e17546805759c81a83 adjust top and bottom sponsor count for "abc_.*" source
H: commit bash
h: xxxxxx

$ git log -- pretty = oneline

cee50d5d7621291b86f628cce4465714d7f9d034 add source

bd14bfa9c495ac739cfd7fb0aedc37cebf25a64c add redirect type

8cfdbf631bb9884968b8e2d6a64af72422fe985f add sponsor transfer log

de13087ef51e57925e77f832b81511305bde0df8 change display area name

a3beaba9e3ff7affff7b018fc7d781d7212d4944 rename GoogleAf * .php to Googleaf * .php

4c41c21c16dab60ebc59a4ad869fad0e7e655551 add sponsor click tracking

cfe01afdb4e29c13bf60d2b38d52f82a4be8dfe0 add monitor js by Quanqi provider for trackingJS click .

5fb43a0a0292f0553f2ded35ba94f6896c5c38c2 add awp for filter source and ignore google mediaparenter robots

765de4caf048790f5c9960e17546805759c81a83 adjust top and bottom sponsor count for "abc_.*" source

H : commit bash

h : xxxxxx

如果想更美观的输出(来自网友的分享):

$git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative

$git log -- graph -- pretty = format : '%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' -- abbrev - commit -- date = relative

git.log.20141017130646

git用各种placeholder来决定各种显示内容:

下面内容来自 这里

# 下面参数定义列表
'%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).

# 下面参数定义列表

'%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 ) .

除此之外, –graph选项可以显示branch的ascii图例。

如果你自己定制了一个喜欢的输出方案,可以保存到git config,或者设置alias以便日后使用。

比如:

$ vi ~/.gitconfig 
[alias]
    logl = log --pretty=oneline 
    logg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative

$ vi ~ / .gitconfig

[ alias ]

logl = log -- pretty = oneline

logg = log -- graph -- pretty = format : '%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' -- abbrev - commit -- date = relative

或者运行下面命令,一样添加到 ~/.gitconfig中:

git config --global alias.logl "log --pretty=oneline"
git config --global alias.logg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"

git config -- global alias .logl "log --pretty=oneline"

git config -- global alias .logg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"

参考文章:

https:///topics/939

http://linux./man/1/git-show

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多