Search code examples
git

Git pretty format colors


I'm trying to set up pretty format colors for Git. From what I can tell version 1.6.0 only recognizes red, green and blue.

$ git log --pretty=format:"%Credred%Creset %Cgreengreen%Creset %Cyellowyellow%Creset %Cblueblue%Creset %Cmagentamagenta%Creset %Ccyancyan%Creset %Cwhitewhite%Creset"
red green %Cyellowyellow%Creset blue %Cmagentamagenta %Ccyancyan %Cwhitewhite

In addition none of the colors work with the parenthesized color format.

Is there a way to list the available pretty format colors for Git?

Unfortunately this is on a legacy SCO OpenServer 5.0.7 machine and the last version of Git released by SCO Skunkworks was 1.6.0.3.


Solution

  • I do not have an old version of git to verify that the colors other than red, blue and green are supported.

    Although, one thing I noticed even with the recent versions of git (like 1.7.10 I used) is that colors other than red, green and blue need to be within parentheses (). For red, green and blue, the parentheses are optional.

    So give this a try:

    git log --pretty=format:"%Credred%Creset %Cgreengreen%Creset %C(Yellow)yellow%Creset %Cblueblue%Creset %C(magenta)magenta%Creset %C(cyan)cyan%Creset %C(white)white%Creset"
    

    The list of colors I'm aware of at least are:

    normal
    black
    red
    green
    yellow
    blue
    magenta
    cyan
    white
    

    It can be combined with one or more of these attributes:

    bold
    dim
    ul
    blink
    reverse
    italic
    strike
    bright  # (Git 2.26, Q1 2020, example: brightred)
    

    If you're trying to change colors using .gitconfig you should be able to specify two colors - foreground and background and you can combine it with an attribute.