当指定--no-color时,不要使用git log --pretty着色ref [英] Don't colorize the refs with git log --pretty when --no-color is specified

查看:303
本文介绍了当指定--no-color时,不要使用git log --pretty着色ref的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Git,使用Windows 7,PowerShell和Posh-Git。我有以下别名设置:

  ls = log --pretty = tformat:%C(yellow)%h \ \%C(绿色)[%ad]%C(青色)\\\\\\\\\\\\\\\\\% code> 

问题在于,当我将输出传送到clip.exe以将其复制到剪贴板时,它还会复制一些字符颜色。稍微阅读一下,我发现你可以添加auto,这样如果指定了 - no-color 选项,它将使用默认颜色。所以现在我有:

  ls = log --pretty = tformat:%C(auto,yellow)%h \ \%C(自动,绿色)[%ad]%C(自动,青色)\\<%cn> \\%C(自动,重置)%s%C(自动)%d 

现在我遇到的问题是显示参考的输出的最后一位。我将颜色设置为auto,以便git将应用分支和标签的默认颜色,但无法弄清楚如何让它符合 - no-color 选项。如果将其设置为%C(自动),则颜色始终显示。我尝试了%C(auto,auto),它与 - no-color 一起工作,但没有它,git抱怨:

 错误:无效颜色值:auto 
致命:无法解析--pretty格式


解决方案


无法弄清楚如何让它遵守 - no-颜色选项。

如果我将它设置为%C(auto),颜色始终显示。


这个问题将在git 2.9.x +(Q3 2016)中得到解决





但使用更新的2.9.x + git版本, - no-color 确实有效:




I'm working with Git, using Windows 7, PowerShell, and Posh-Git. I have the following alias setup:

ls = log --pretty=tformat:"%C(yellow)%h\\ %C(green)[%ad]%C(cyan)\\ <%cn>\\ %C(reset)%s%C(auto)%d"

The problem was that when I pipe the output to clip.exe to copy it to the clipboard, it also copies some characters for the colors. A little reading and I found you could add "auto," so that it would use the default colors if the --no-color option is specified. So now I have:

ls = log --pretty=tformat:"%C(auto,yellow)%h\\ %C(auto,green)[%ad]%C(auto,cyan)\\ <%cn>\\ %C(auto,reset)%s%C(auto)%d"

The problem I now have is the last bit of the output showing the refs. I have the color set to auto so that git will apply the default colors for branches and tags, but can't figure out how to get it to respect the --no-color option. If I set it to %C(auto) the colors show all the time. I tried %C(auto,auto) and that works with --no-color, but without it git complains:

error: invalid color value: auto
fatal: unable to parse --pretty format

解决方案

can't figure out how to get it to respect the --no-color option.
If I set it to %C(auto), the colors show all the time.

This will be fixed in git 2.9.x+ (Q3 2016)

See commit b15a3e0 (27 May 2016) by Edward Thomson (ethomson).
(Merged by Junio C Hamano -- gitster -- in commit 1b3d14c, 20 Jun 2016)

format_commit_message: honor color=auto for %C(auto)

git-log(1) documents that when specifying the %C(auto) format placeholder will "turn on auto coloring on the next %placeholders until the color is switched again."

However, when %C(auto) is used, the present implementation will turn colors on unconditionally (even if the color configuration is turned off for the current context - for example, --no-color was specified or the color is auto and the output is not a tty).

Update format_commit_one to examine the current context when a format string of %C(auto) is specified, which ensures that we will not unconditionally write colors.
This brings that behavior in line with the behavior of %C(auto,<colorname>), and allows the user the ability to specify that color should be displayed only when the output is a tty.

This is what you see with git-for-windows 2.9.0

But with a more recent 2.9.x+ git version, --no-color does work:

这篇关于当指定--no-color时,不要使用git log --pretty着色ref的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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