git log 带颜色 彩色显示
log日志,默认显示是黑白的,看这个不方便。加点颜色显示看着更方便。
一、颜色示例
1.默认显示:
git log -1 --pretty="format:%h %s"

2.加彩色显示:
git log -1 --pretty="format:%h %Cgreen %s %Creset"

%h %s 是显示log的内容。具体,参看文末,附录三
%C 定制颜色的固定开始,类似shell变量的左边 $ 符号
green 绿色
reset 颜色结束,类似变量的右括号
3.颜色和输出内容不能分开时,用圆括号减少歧义
git log -1 --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

二、设置全局变量
每次使用,手写一遍,不方便,可以加入到全局变量配置文件中,创建一个别名。
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
这条配置会写入到Linux 的 ~/.gitconfig 文件中
git lg -1
看和手写的一样了,以后就不用麻烦

3.还有 auto 选项
%C(auto,blue)Hello%C(auto,reset)
三、给其他命令上颜色
1.给 branch 命令设置颜色,将以下内容加入 ~/.gitconfig 文件中
[color "branch"]
current = yellow reverse
local = yellow
remote = green
说明:
reverse 加背景色
current 当前分支
local 本地分支
remote 远程分支
默认颜色:

设置颜色:

四、设置字体属性
git log -1 --graph --pretty=format:'%C(red reverse)%h'

字体说明,详见:附录二
附录一:颜色切换到
| 参数 | 说明 |
|---|---|
| %C(…) | 制定颜色, as described in color.branch.* config option |
| %C(auto) | 默认 |
| %Cnormal | 默认 |
| %Cred 或 %C(red) | 红色 |
| %Cgreen 或 %C(green) | 绿色 |
| %Cblue | 蓝色 |
| %Cyellow | 黄色 |
| %Ccyan | 青色 |
| %Cblack | 黑色 |
| %Cmagenta | 紫红色 |
| %Cwhite | 白色 |
| %Creset | 重设颜色 |
附录二:字体属性
| 参数 | 说明 |
|---|---|
| %Cbold | 黑色 |
| %Cdim | 暗色 |
| %Cul | 列表 |
| %Cblink | 闪烁 |
| %Creverse | 背景色 |
附录三
最新参数:https://www.cnblogs.com/wutou/p/17538388.html
| 参数 | 说明 |
|---|---|
| %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 | 过滤commit信息的标题使之可以作为文件名 |
| %b | commit信息内容 |
| %N | commit notes |
| %gD | reflog selector, e.g., refs/stash@ |
| %gd | shortened reflog selector, e.g., stash@ |
| %gs | reflog subject |
| %m | left, right or boundary mark |
| %n | 换行 |
| %% | a raw % |
| %x00 | print a byte from a hex code |
| %w([<w>[,<i1>[,<i2>]]]) | switch line wrapping, like the -w option of git-shortlog(1). |
附录四
git log -xx --xxxx 参数【汇总】 https://www.cnblogs.com/wutou/p/17581606.html
参考:
https://www.coder.work/article/1522538
https://blog.csdn.net/CalledJoker/article/details/119996300
https://www.cnblogs.com/sepmaple/p/9482591.html
https://www.likecs.com/show-308237631.html
https://www.oomake.com/question/1477634
http://wed.xjx100.cn/news/194898.html?action=onClick
浙公网安备 33010602011771号