What does git-config(1) mean when it says “colors

2019-04-27 00:59发布

问题:

I'm outputting to a terminal, but Git is not correctly detecting that I'm outputting to a terminal, for the purposes of coloring the output. My question is, what does git-config(1) really mean when it says "colors are used only when the output is to a terminal" (this phrase appears at the end of multiple config descriptions, such as for color.ui and color.branch)? In other words, how does Git decide whether or not it's outputting to a terminal, and how do I change my environment settings to inform Git that my terminal is indeed a terminal?

Specifics:
I'm using rxvt terminal with Cygwin on Windows. I also have MSysGit installed. When I make the Git config settings:

[color]
    ui = auto
    branch = auto
    status = auto

there is still no color in my terminal output. However, when I switch to

[color]
    ui = always
    branch = always
    status = always

then there is correct colored output. However, I need to switch back to "auto", not "always", in order to handle the actual non-terminal cases correctly. So for the purpose of making "auto" work correctly: How do I change my environment to make Git recognize that my rxvt+Cygwin is a terminal capable to supporting color?

(PS. I can't use the Cygwin version of Git due to much bigger problems than this relatively minor color issue. Please don't reply telling me to switch to the Cygwin version.)

Thanks for your help!

回答1:

It might be worth looking at this question which covers detecting difference between output going to a terminal (i.e. tty session) vs it being redirected to another process. I'm assuming that this is what git means in its phrasing of "going to a terminal", that the output is in fact going to a tty session.