简体   繁体   English

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

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

Using Windows 10 Pro 64-bit I found a nice command to list the Git history, showing HEAD , branches, and tags as stand-out colors.使用 64 位 Windows 10 专业版,我发现了一个很好的命令来列出 Git 历史记录,将HEAD 、分支和标签显示为突出的颜色。 Nice!好的!

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

But I don't see any dates or authors!但我没有看到任何日期或作者! So I find another nice command:所以我找到了另一个不错的命令:

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

Also very nice---now I can see dates and authors.也很不错——现在我可以看到日期和作者了。 But all the pretty colors are gone (except for the graph).但是所有漂亮的颜色都消失了(除了图表)。 HEAD , branches, and tags are all the same color as the rest of the log, making it hard to pick them out. HEAD 、分支和标签都与日志的其余部分颜色相同,因此很难将它们挑出来。

How do I get the colors back for the commit pointers while keeping the date and authors?如何在保留日期和作者的同时恢复提交指针的颜色?

This should do what you're looking for: 这应该可以满足您的需求:

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

在此处输入图片说明

Taken from this post 取自这篇文章

Add the git log --decorate --graph and it will display branches, tags etc. 添加git log --decorate --graph ,它将显示分支,标签等。

--decorate [=short|full|no] --decorate [= short | full | no]

Print out the ref names of any commits that are shown. 打印显示的所有提交的引用名称。 If short is specified, the ref name prefixes refs/heads/, refs/tags/ and refs/remotes/ will not be printed. 如果指定了short,则不会打印ref名称的前缀refs / heads /,refs / tags /和refs / remotes /。 If full is specified, the full ref name (including prefix) will be printed. 如果指定了full,则将打印完整的引用名称(包括前缀)。 The default option is short 默认选项是short

--graph

Draw a text-based graphical representation of the commit history on the left hand side of the output. 在输出的左侧绘制提交历史记录的基于文本的图形表示。 This may cause extra lines to be printed in between commits, in order for the graph history to be drawn properly 这可能会导致在两次提交之间打印额外的行,以便正确绘制图形历史记录


For windows

format:<string>

The format: format allows you to specify which information you want to show. 格式:format允许您指定要显示的信息。 It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \\n. 它的工作方式类似于printf格式,但值得注意的例外是您使用%n而不是\\ n换行。

Eg, format: The author of %h was %an, %ar%nThe title was >>%s<<%n would show something like this: 例如,格式: 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.<<

You can use the log format flag 您可以使用日志格式标志

# 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 : The placeholders are

%C(…): color specification, as described in color.branch.* config option; %C(…):颜色规范,如color.branch。*配置选项中所述; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). 添加auto时,只有在启用日志输出的颜色(通过color.diff,color.ui或--color并在要连接到终端时遵守前者的自动设置)的情况下,开始时才会发出颜色。 auto alone (ie %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again. 单独使用auto(即%C(auto))将在下一个占位符上启用自动着色,直到再次切换颜色为止。

%C(…): color specification, as described in color.branch.* config option; %C(…):颜色规范,如color.branch。*配置选项中所述; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). 添加auto时,只有在启用日志输出的颜色(通过color.diff,color.ui或--color并在要连接到终端时遵守前者的自动设置)的情况下,开始时才会发出颜色。 auto alone (ie %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again. 单独使用auto(即%C(auto))将在下一个占位符上启用自动着色,直到再次切换颜色为止。

%Cblue: switch color to blue %Cblue:将颜色切换为蓝色
%Cgreen: switch color to green %Cgreen:将颜色切换为绿色
%Cred: switch color to red %Cred:将颜色切换为红色
%Creset: reset color %Creset:重置颜色
%D: ref names without the " (", ")" wrapping. %D:引用名称不带“(”,“)”换行。
%G?: show "G" for a Good signature, %G?:显示“ G”以获得良好的签名,
"B" for a Bad signature, “ B”代表错误签名,
"U" for a good, untrusted signature and “ U”代表良好且不受信任的签名,并且
"N" for no signature “ N”,无签名
%GG: raw verification message from GPG for a signed commit %GG:来自GPG的原始验证消息,用于已签名的提交
%GK: show the key used to sign a signed commit %GK:显示用于签署已签名提交的密钥
%GS: show the name of the signer for a signed commit %GS:显示签名提交的签名者的名字
%H: commit hash %H:提交哈希
%N: commit notes %N:提交笔记
%P: parent hashes %P:父哈希
%T: tree hash %T:树哈希
%aD: author date, RFC2822 style %aD:作者日期,RFC2822样式
%aE: author email (respecting .mailmap, see git-shortlog(1) or git-blame(1)) %aE:作者电子邮件(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%aI: author date, strict ISO 8601 format %aI:作者日期,严格的ISO 8601格式
%aN: author name (respecting .mailmap, see git-shortlog(1) or git-blame(1)) %aN:作者姓名(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%ad: author date (format respects --date= option) %ad:作者日期(格式方面--date =选项)
%ae: author email %ae:作者电子邮件
%ai: author date, ISO 8601-like format %ai:作者日期,类似于ISO 8601的格式
%an: author name %an:作者姓名
%ar: author date, relative %ar:作者日期,相对
%at: author date, UNIX timestamp %at:作者日期,UNIX时间戳
%b: body %b:身体
%cD: committer date, RFC2822 style %cD:提交者日期,RFC2822样式
%cE: committer email (respecting .mailmap, see git-shortlog(1) or git-blame(1)) %cE:提交者电子邮件(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%cI: committer date, strict ISO 8601 format %cI:提交者日期,严格的ISO 8601格式
%cN: committer name (respecting .mailmap, see git-shortlog(1) or git-blame(1)) %cN:提交者名称(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%cd: committer date (format respects --date= option) %cd:提交者日期(格式方面--date =选项)
%ce: committer email %ce:提交者电子邮件
%ci: committer date, ISO 8601-like format %ci:提交者日期,类似于ISO 8601的格式
%cn: committer name %cn:提交者名称
%cr: committer date, relative %cr:提交者日期(相对)
%ct: committer date, UNIX timestamp %ct:提交者日期,UNIX时间戳
%d: ref names, like the --decorate option of git-log(1) %d:引用名称,例如git-log(1)的--decorate选项
%e: encoding %e:编码
%f: sanitized subject line, suitable for a filename %f:清理的主题行,适用于文件名
%gD: reflog selector, eg, refs/stash@{1} %gD:引用日志选择器,例如refs / stash @ {1}
%gE: reflog identity email (respecting .mailmap, see git-shortlog(1) or git-blame(1)) %gE: reflog身份电子邮件(尊重.mailmap,请参阅git-shortlog(1)或git-blame(1))
%gN: reflog identity name (respecting .mailmap, see git-shortlog(1) or git-blame(1)) %gN:引用日志标识名称(使用.mailmap,请参阅git-shortlog(1)或git-blame(1))
%gd: shortened reflog selector, eg, stash@{1} %gd:缩短的引用日志选择器,例如stash @ {1}
%ge: reflog identity email %ge: reflog身份电子邮件
%gn: reflog identity name %gn: reflog身份名称
%gs: reflog subject %gs:主题
%h: abbreviated commit hash %h:缩写提交哈希
%m: left, right or boundary mark %m:左,右或边界标记
%n: newline %n:换行符
%p: abbreviated parent hashes %p:缩写的父哈希
%s: subject %s:主题
%t: abbreviated tree hash %t:缩写树哈希
%w([<w>[,<i1>[,<i2>]]]): switch line wrapping, like the -w option of git-shortlog(1). %w([<w>[,<i1>[,<i2>]]]):切换换行,就像git-shortlog(1)的-w选项一样。
%x00: print a byte from a hex code %x00:从十六进制代码打印字节


On unix

Output of the .githelprs script:

在此处输入图片说明

You can wrap your format string with %C(auto) and %C(reset) to color the output automatically, like so:您可以使用%C(auto)%C(reset)包装格式字符串以%C(auto)为输出着色,如下所示:

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

So, using the format you provided:因此,使用您提供的格式:

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

It will use git's default color for things like branches (remote in red, local in green, HEAD in cyan etc) and commit refs.它将使用 git 的默认颜色来处理分支(远程为红色,本地为绿色,HEAD 为青色等)和提交参考。

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

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