git log输出中的数据和时间使用不同的颜色 [英] different color for data and time in git log output

查看:60
本文介绍了git log输出中的数据和时间使用不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 git log 输出中为日期和时间显示不同的颜色.

I am trying to show different color for date and time in the git log output.

当前我正在使用 git config --global alias.l'log --pretty = format:''%C(#d33682)%h%C(#b58900)%cd%C(#6c71c4)%ce%C(#2aa198)%s%C(#cb4b16)"--date = format:%d-%m-%Y%I-%M-%S"'

因此,我尝试了 git config --global alias.l'log --pretty = format:%C(#d33682)%h%cd%C(#6c71c4)%ce%C(#2aa198)%s%C(#cb4b16)"--date = format:%C(#b58900)%d-%m-%Y%C(#859900)%I-%M-%S"'

-date = format:中的颜色不适合我.

有什么建议吗?

推荐答案

在这里,您有两个选择.第一个方法是使用%cs ,它以%Y-%m-%d 格式返回提交日期,并根据在-date 中传递的格式设置时间格式.代码>:

Here you have two options. First one is using %cs which return commit date in format %Y-%m-%d and formats time according to format passed in --date:

git log --pretty=format:"%C(#d33682)%h %Cred%cs %C(#b58900)%cd %C(#6c71c4)%ce %C(#2aa198)%s %C(#cb4b16)" --date=format:"%I-%M-%S"

另一个选择是将输出截断两次,一次是从右截断,另一次是从左截断.这将添加那些 .. ,表明该列被截断了……

Another option wound be to truncate output twice, one time from right, another from left. This one would add those .. indicating that the column was truncated…

git log --pretty=format:"%C(#d33682)%h %Cred%<(12,trunc)%cd %C(#b58900)%<(10,ltrunc)%cd %C(#6c71c4)%ce %C(#2aa198)%s %C(#cb4b16)" --date=format:"%d-%m-%Y %I-%M-%S"

其他选项,您可以使用任何希望的日期时间格式来保留其他工具的颜色;)

Other option, in which you could use any datetime format you wish is to left handling colors for other tool ;)

git log --pretty=format:"%h %cd %ce %s" --date=format:"%d-%m-%Y %I-%M-%S" | awk '{printf "\033[1;31m" $1 "\033[0m \033[1;32m" $2 "\033[0m \033[1;33m" $3 "\033[0m \033[1;34m" $4 "\033[0m \033[1;35m"; $1=$2=$3=$4=""; print substr($0,5)}'

这篇关于git log输出中的数据和时间使用不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆