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

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


当前回答

例如,参见https://web.archive.org/web/20080506194329/http://www.arthurkoziel.com/2008/05/02/git-configuration/

有趣的是

彩色的输出: Git配置全局颜色。分支汽车 Git配置全局颜色。diff汽车 Git配置——global color.interactive auto Git配置全局颜色。地位的汽车

其他回答

例如,参见https://web.archive.org/web/20080506194329/http://www.arthurkoziel.com/2008/05/02/git-configuration/

有趣的是

彩色的输出: Git配置全局颜色。分支汽车 Git配置全局颜色。diff汽车 Git配置——global color.interactive auto Git配置全局颜色。地位的汽车

如果您要求,Git会自动为大部分输出上色。你可以非常具体地说明你想要什么颜色以及如何着色;但是要打开所有默认的终端颜色,请设置颜色。UI为true:

git config --global color.ui true

GIT默认使用彩色输出,但在某些系统上,如CentOS,它是不启用的。您可以像这样启用它

git config --global color.ui  true 
git config --global color.ui  false 
git config --global color.ui  auto 

您可以从这里选择所需的命令。

这里——global是可选的,用于为系统中的每个存储库应用操作。如果你只想为当前存储库应用着色,那么你可以这样做-

 git config color.ui  true 

添加到你的.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

正如@VonC所指出的,color。ui从Git 1.8.4开始默认为auto


从Unix和Linux Stackexchange问题如何着色输出的git?以及@Evgeny的回答:

git config --global color.ui auto

这颜色。UI是一个元配置,包括所有不同的颜色。*配置可用的git命令。这在git帮助配置中有深入的解释。

基本上,这比设置不同的颜色更简单,更经得起考验。*单独设置。

git配置文档的深入解释:

color.ui: This variable determines the default value for variables such as color.diff and color.grep that control the use of color per command family. Its scope will expand as more commands learn configuration to set a default for the --color option. Set it to always if you want all output not intended for machine consumption to use color, to true or auto if you want such output to use color when written to the terminal, or to false or never if you prefer git commands not to use color unless enabled explicitly with some other configuration or the --color option.