Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...