我最近看到Windows中的git控制台是有颜色的,例如,绿色表示添加,红色表示删除等等。我怎么给git控制台上色呢?

要安装它,我使用命令:$ sudo apt-get install git-core


当前回答

改进win10上Git“branch-type”的颜色:在所有示例中显示命令Git branch -avv


1. Git默认配色方案:

git config --system --remove-section color.branch


2. 在本页的另一个答案中给出的分支颜色:

git config --system color.branch.local    "yellow"
git config --system color.branch.current  "yellow reverse"
git config --system color.branch.remote   "green"


3.可能改进的分支配色方案:

git config --system color.branch.local    "yellow"
git config --system color.branch.current  "brightwhite yellow"
git config --system color.branch.remote   "normal green"
git config --system color.branch.upstream "brightwhite cyan"


4. 自己制作:

指定前景色和(可选的)背景色。在Windows 10中起作用的颜色集根据下面的正则表达式给出(是的,你可以使用brightblack,它实际上非常有用):

(normal|(bright)?(black|red|green|yellow|blue|magenta|cyan|white))

据我所知,在Windows 10控制台上,暗淡选项(见底部的文档链接)没有任何作用,而粗体选项与明亮*颜色具有相同的效果。现在回想一下示例中显示的配置语法:

git config <config-type> color.branch.<slot>  "<fg> <bg>"

参数<config-type>通常是——system或——global。如果省略,指定的颜色将只应用于当前的repo。使用刚才详细介绍的颜色名称,您可以为特定的分支类型设置前景色<fg>和背景<bg>颜色,其中<slot>是以下之一:

电流(当前支路) 本地(本地分支机构) Remote (refs/remotes/中的远程跟踪分支) 上游(上游跟踪分支) 平原

像往常一样,你可以通过以下命令显示你的整个git配置,其中将包括你在这里设置的任何选项:

git config -l --show-origin

注意还有一组与日志输出颜色相关的配置选项(这里不讨论):

git config --system color.decorate.(branch|remoteBranch|tag|stash|HEAD|grafted) <color>

参考:https://git-scm.com/docs/git-config

其他回答

让我们假设您希望当前分支是黄色的 所有其他分支都是青色粗体。 我正在考虑您希望这些更改在本地完成,即在您当前的存储库中,而不是在您的系统中存在的所有存储库。 使用“cd .git”进入。git文件,然后打开“config”文件。 在配置文件中输入以下内容,而不更改配置文件中的任何其他内容。

 [color]
         ui=true
    [color "branch"]
         local=cyan bold 
         current=yellow bold

然后保存配置文件。 打开git控制台,执行git分支。 你会发现其中的差别

在你的~/。Gitconfig文件,简单地添加这个:

[color]
  ui = auto

它负责所有的git命令。

另一种方法是编辑.gitconfig(如果不存在就创建一个),例如:

vim ~/.gitconfig

然后加上:

[color]
  diff = auto
  status = auto
  branch = auto

改进win10上Git“branch-type”的颜色:在所有示例中显示命令Git branch -avv


1. Git默认配色方案:

git config --system --remove-section color.branch


2. 在本页的另一个答案中给出的分支颜色:

git config --system color.branch.local    "yellow"
git config --system color.branch.current  "yellow reverse"
git config --system color.branch.remote   "green"


3.可能改进的分支配色方案:

git config --system color.branch.local    "yellow"
git config --system color.branch.current  "brightwhite yellow"
git config --system color.branch.remote   "normal green"
git config --system color.branch.upstream "brightwhite cyan"


4. 自己制作:

指定前景色和(可选的)背景色。在Windows 10中起作用的颜色集根据下面的正则表达式给出(是的,你可以使用brightblack,它实际上非常有用):

(normal|(bright)?(black|red|green|yellow|blue|magenta|cyan|white))

据我所知,在Windows 10控制台上,暗淡选项(见底部的文档链接)没有任何作用,而粗体选项与明亮*颜色具有相同的效果。现在回想一下示例中显示的配置语法:

git config <config-type> color.branch.<slot>  "<fg> <bg>"

参数<config-type>通常是——system或——global。如果省略,指定的颜色将只应用于当前的repo。使用刚才详细介绍的颜色名称,您可以为特定的分支类型设置前景色<fg>和背景<bg>颜色,其中<slot>是以下之一:

电流(当前支路) 本地(本地分支机构) Remote (refs/remotes/中的远程跟踪分支) 上游(上游跟踪分支) 平原

像往常一样,你可以通过以下命令显示你的整个git配置,其中将包括你在这里设置的任何选项:

git config -l --show-origin

注意还有一组与日志输出颜色相关的配置选项(这里不讨论):

git config --system color.decorate.(branch|remoteBranch|tag|stash|HEAD|grafted) <color>

参考:https://git-scm.com/docs/git-config

添加到你的.gitconfig文件下一个代码:

[color]
    ui = auto
[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
[color "status"]
    added = yellow
    changed = green
    untracked = cyan