如何为Git控制台着色?

Mau*_*ras 364 git console colors

我最近看到gitWindows 中的控制台是彩色的,例如绿色用于添加,红色用于删除等.如何为我的git控制台着色?

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

Joe*_*rra 669

正如指出@VonC,color.ui默认为auto自git的1.8.4.不是太快释放;)


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

git config --global color.ui auto
Run Code Online (Sandbox Code Playgroud)

color.ui是一种元配置,包括命令color.*可用的所有各种配置git.这将在深入解释git help config.

所以基本上它比color.*单独设置不同的设置更容易,更具前瞻性.

git config文档中的深入解释:

color.ui:此变量确定的变量,如缺省值color.diffcolor.grep该控制使用每命令家庭颜色.随着更多命令学习配置以设置--color选项的默认值,其范围将扩展.设置它always,如果你想所有的输出不适合机消费使用的颜色,来true或者auto如果你想这样的输出,当写入到终端,或使用颜色falsenever如果你喜欢Git命令不使用的颜色,除非有一些明确启用其他配置或--color选项.

  • 这也适用于OSX,而​​不仅仅是问题所在的Linux (11认同)
  • @Skeptor:不,`auto`就足够了. (6认同)
  • 它是持久的,因为它将`ui = auto`条目添加到用户的`〜/ .gitconfig`文件中的`[color]`部分. (5认同)
  • @Phani:是的,它是持久的. (2认同)

Kin*_*nch 54

例如,请参阅http://www.arthurkoziel.com/2008/05/02/git-configuration/

有趣的是

彩色输出:

git config --global color.branch auto
git config --global color.diff auto
git config --global color.interactive auto
git config --global color.status auto
Run Code Online (Sandbox Code Playgroud)

  • 我正在使用旧版本的git并且设置`color.ui auto`对我来说不起作用,这样做了.谢谢. (3认同)

小智 29

添加到.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
Run Code Online (Sandbox Code Playgroud)


Tan*_*may 7

如果你要求,Git会自动为其大部分输出着色.你可以非常具体地了解你想要的颜色和方式; 但要打开所有默认终端着色,请将color.ui设置为true:

git config --global color.ui true
Run Code Online (Sandbox Code Playgroud)


Gle*_*den 7

改进 Windows 10 上的 Git“分支类型”颜色:显示所有示例的

命令... git branch -avv


1.Git默认配色方案:

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

在此输入图像描述


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

git config --system color.branch.local“黄色”
git config --system color.branch.current“黄色反转”
git config --system color.branch.remote“绿色”

在此输入图像描述


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

git config --system color.branch.local“黄色”
git config --system color.branch.current“亮白黄色”
git config --system color.branch.remote "普通绿色"
git config --system color.branch.upstream“亮白青色”

在此输入图像描述


4. 自己制作:

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

(正常|(亮)?(黑色|红色|绿色|黄色|蓝色|洋红色|青色|白色))

据我所知,该dim选项(请参阅底部的文档链接)在 Windows 10 控制台中不起任何作用,并且该bold选项与颜色具有相同的效果bright*。现在回想一下示例中显示的配置语法:

git config <config-type> color.branch.<slot>  "<fg> <bg>"
Run Code Online (Sandbox Code Playgroud)

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

  • current(当前分行)
  • local(当地分支机构)
  • remote(refs/remotes/ 中的远程跟踪分支)
  • upstream(上游跟踪分支)
  • plain

与往常一样,您可以通过以下命令显示整个 git 配置,其中包括您按照此处所述设置的任何选项:

git config -l --show-origin
Run Code Online (Sandbox Code Playgroud)

请注意,还有一组与日志输出颜色相关的配置选项(此处未讨论):

git config --system color.decorate.(branch|remoteBranch|tag|stash|HEAD|grafted) <color>
Run Code Online (Sandbox Code Playgroud)

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


Von*_*onC 6

在Ubuntu或任何其他平台(是的,Windows也是!); 开始git1.8.4,这是公布的2013年8月23日,你会不会做任何事情:

许多教程教会用户将"color.ui"设置为"auto",这是你设置" user.name/email"将自己介绍给Git 之后的第一件事.现在变量默认为" auto".

所以你会默认看到颜色.

  • (好吧,甚至Windows,取决于终端:http://stackoverflow.com/a/12133244/6309) (2认同)
  • 在2014年使用Ubuntu,安装了git并且仍然必须运行`git config --global color.ui auto`.我的Mac也是如此,默认为"auto"的唯一一个是我的Windows PC上的Git Bash. (2认同)

Chu*_* Lu 6

在您的~/.gitconfig文件中,只需添加以下内容:

[color]
  ui = auto
Run Code Online (Sandbox Code Playgroud)

它会处理所有git命令.


atu*_*pal 5

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

vim ~/.gitconfig
Run Code Online (Sandbox Code Playgroud)

然后添加:

[color]
  diff = auto
  status = auto
  branch = auto
Run Code Online (Sandbox Code Playgroud)

  • 正如@ chuntao-lu提到的`[color] ui = auto`就足够了. (3认同)

小智 5

GIT默认使用彩色输出,但在像CentOS这样的系统上它没有启用.您可以像这样启用它

git config --global color.ui  true 
git config --global color.ui  false 
git config --global color.ui  auto 
Run Code Online (Sandbox Code Playgroud)

您可以从此处选择所需的命令.

这里--global是可选的,可以为系统中的每个存储库应用操作.如果您只想为当前存储库应用着色,那么您可以执行以下操作 -

 git config color.ui  true 
Run Code Online (Sandbox Code Playgroud)