Git pretty format colors

前端 未结 5 726
醉酒成梦
醉酒成梦 2020-12-07 09:36

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:\"%Cre         


        
5条回答
  •  旧巷少年郎
    2020-12-07 09:44

    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.

提交回复
热议问题