Am 09.10.2016 um 07:43 schrieb Tom Hale:
$ ~/repo/git/git --version
git version 2.10.0.GIT

The `git-log` man page says:

`auto` alone (i.e.  %C(auto)) will turn on auto coloring on the next
placeholders until the color is switched again.

In this example:

http://i.imgur.com/y3yLxk7.png

I turn on auto colouring for green, but it seems that this is not being
respected when piped through `cat`.

Am I misunderstanding the manual?

So this colors the ref name decoration and the short hash:

        $ git log -n1 --format="%C(auto)%d %C(auto)%Cgreen%h"

And this only colors the short hash:

        $ git log -n1 --format="%C(auto)%d %C(auto)%Cgreen%h" | cat

%C(auto) respects the color-related configuration settings; that's mentioned on the man page for git log in the section on %C(...). You probably have color.ui=auto or color.diff=auto in your config, which means that output to terminals is to be colored, but output to files and pipes isn't. You could override that setting e.g. by adding the command line option --color=always.

%Cgreen emits color codes unconditionally. %C(auto,green) would respect the config settings.

Your second %C(auto) has no effect because it is overridden by the immediately following %Cgreen.

You may want to add a %Creset at the end to avoid colors bleeding out over the end of the line. You can see that happening e.g. with:

        $ git log -n3 --format="normal %C(green)green" | cat

Without cat bash seems to add a reset automatically.

René

Reply via email to