繁体   English   中英

git log 中的颜色和作者在 Windows 上?

[英]Colors and authors in git log on Windows?

使用 64 位 Windows 10 专业版,我发现了一个很好的命令来列出 Git 历史记录,将HEAD 、分支和标签显示为突出的颜色。 好的!

git log --oneline --decorate --graph --all

但我没有看到任何日期或作者! 所以我找到了另一个不错的命令:

git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

也很不错——现在我可以看到日期和作者了。 但是所有漂亮的颜色都消失了(除了图表)。 HEAD 、分支和标签都与日志的其余部分颜色相同,因此很难将它们挑出来。

如何在保留日期和作者的同时恢复提交指针的颜色?

这应该可以满足您的需求:

git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all

在此处输入图片说明

取自这篇文章

添加git log --decorate --graph ,它将显示分支,标签等。

--decorate [= short | full | no]

打印显示的所有提交的引用名称。 如果指定了short,则不会打印ref名称的前缀refs / heads /,refs / tags /和refs / remotes /。 如果指定了full,则将打印完整的引用名称(包括前缀)。 默认选项是short

--graph

在输出的左侧绘制提交历史记录的基于文本的图形表示。 这可能会导致在两次提交之间打印额外的行,以便正确绘制图形历史记录


For windows

format:<string>

格式:format允许您指定要显示的信息。 它的工作方式类似于printf格式,但值得注意的例外是您使用%n而不是\\ n换行。

例如,格式: The author of %h was %an, %ar%nThe title was >>%s<<%n将显示如下内容:

The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<

您可以使用日志格式标志

# print out the git log
git log 

# print out the branches split and merge points
--graph 

# use the --pretty=format:... to choose which data to extract from the log
# (commit) entry and print it out.

# Set colors with the %C<color> & %Creset for resetting back to the default color

The placeholders are

%C(…):颜色规范,如color.branch。*配置选项中所述; 添加auto时,只有在启用日志输出的颜色(通过color.diff,color.ui或--color并在要连接到终端时遵守前者的自动设置)的情况下,开始时才会发出颜色。 单独使用auto(即%C(auto))将在下一个占位符上启用自动着色,直到再次切换颜色为止。

%C(…):颜色规范,如color.branch。*配置选项中所述; 添加auto时,只有在启用日志输出的颜色(通过color.diff,color.ui或--color并在要连接到终端时遵守前者的自动设置)的情况下,开始时才会发出颜色。 单独使用auto(即%C(auto))将在下一个占位符上启用自动着色,直到再次切换颜色为止。

%Cblue:将颜色切换为蓝色
%Cgreen:将颜色切换为绿色
%Cred:将颜色切换为红色
%Creset:重置颜色
%D:引用名称不带“(”,“)”换行。
%G?:显示“ G”以获得良好的签名,
“ B”代表错误签名,
“ U”代表良好且不受信任的签名,并且
“ N”,无签名
%GG:来自GPG的原始验证消息,用于已签名的提交
%GK:显示用于签署已签名提交的密钥
%GS:显示签名提交的签名者的名字
%H:提交哈希
%N:提交笔记
%P:父哈希
%T:树哈希
%aD:作者日期,RFC2822样式
%aE:作者电子邮件(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%aI:作者日期,严格的ISO 8601格式
%aN:作者姓名(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%ad:作者日期(格式方面--date =选项)
%ae:作者电子邮件
%ai:作者日期,类似于ISO 8601的格式
%an:作者姓名
%ar:作者日期,相对
%at:作者日期,UNIX时间戳
%b:身体
%cD:提交者日期,RFC2822样式
%cE:提交者电子邮件(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%cI:提交者日期,严格的ISO 8601格式
%cN:提交者名称(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%cd:提交者日期(格式方面--date =选项)
%ce:提交者电子邮件
%ci:提交者日期,类似于ISO 8601的格式
%cn:提交者名称
%cr:提交者日期(相对)
%ct:提交者日期,UNIX时间戳
%d:引用名称,例如git-log(1)的--decorate选项
%e:编码
%f:清理的主题行,适用于文件名
%gD:引用日志选择器,例如refs / stash @ {1}
%gE: reflog身份电子邮件(尊重.mailmap,请参阅git-shortlog(1)或git-blame(1))
%gN:引用日志标识名称(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%gd:缩短的引用日志选择器,例如stash @ {1}
%ge: reflog身份电子邮件
%gn: reflog身份名称
%gs:主题
%h:缩写提交哈希
%m:左,右或边界标记
%n:换行符
%p:缩写的父哈希
%s:主题
%t:缩写树哈希
%w([<w>[,<i1>[,<i2>]]]):切换换行,就像git-shortlog(1)的-w选项一样。
%x00:从十六进制代码打印字节


On unix

Output of the .githelprs script:

在此处输入图片说明

您可以使用%C(auto)%C(reset)包装格式字符串以%C(auto)为输出着色,如下所示:

%C(auto)<insert your formatting here>%C(reset)

因此,使用您提供的格式:

git log --pretty=format:"%C(auto)%h %ad | %s%d [%an]%C(reset)" --graph --date=short

它将使用 git 的默认颜色来处理分支(远程为红色,本地为绿色,HEAD 为青色等)和提交参考。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM