如何为Git控制台着色?

本文翻译自:How to color the Git console?

I recently saw that the git console in Windows is colored, eg Green for additions, red for deletions, etc. How do I color my git console like that? 我最近看到Windows中的git控制台是彩色的,例如Green用于添加,红色用于删除等。我如何为我的git控制台着色?

To install it, I used the command: $ sudo apt-get install git-core 要安装它,我使用了命令: $ sudo apt-get install git-core


#1楼

参考:https://stackoom.com/question/k9Hs/如何为Git控制台着色


#2楼

For example see https://web.archive.org/web/20080506194329/http://www.arthurkoziel.com/2008/05/02/git-configuration/ 例如,请参阅https://web.archive.org/web/20080506194329/http://www.arthurkoziel.com/2008/05/02/git-configuration/

The interesting part is 有趣的是

Colorized output: 彩色输出:

 git config --global color.branch auto git config --global color.diff auto git config --global color.interactive auto git config --global color.status auto 

#3楼

As noted by @VonC , color.ui defaults to auto since Git 1.8.4 正如指出@VonCcolor.ui默认为auto从Git的1.8.4


From the Unix & Linux Stackexchange question How to colorize output of git? 从Unix和Linux Stackexchange问​​题如何着色git的输出? and the answer by @Evgeny : 以及@Evgeny回答

git config --global color.ui auto

The color.ui is a meta configuration that includes all the various color.* configurations available with git commands. color.ui是一个元配置,包含git命令可用的所有各种color.*配置。 This is explained in-depth in git help config . 这在git help config有详细解释。

So basically it's easier and more future proof than setting the different color.* settings separately. 所以基本上它比分别设置不同的color.*设置更容易,更具前瞻性。

In-depth explanation from the git config documentation : git config文档深入解释:

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. color.ui :此变量确定控制每个命令族颜色使用的变量(如color.diffcolor.grep的默认值。 Its scope will expand as more commands learn configuration to set a default for the --color option. 随着更多命令学习配置以设置--color选项的默认值,其范围将扩展。 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. 将其设置为always ,如果你想不用于机器消耗所有输出使用的颜色,以trueauto ,如果你想这样的输出使用的颜色,当写入到终端,或falsenever如果你喜欢Git命令不使用颜色除非使用其他配置或--color选项明确启用。


#4楼

In Ubuntu or any other platform (yes, Windows too!); 在Ubuntu或任何其他平台(是的,Windows也是!); starting git1.8.4 , which was released 2013-08-23 , you won't have to do anything : 2013-08-23发布的 git1.8.4开始, 你将不需要做任何事情

Many tutorials teach users to set "color.ui" to "auto" as the first thing after you set " user.name/email " to introduce yourselves to Git. 许多教程教会用户将“color.ui”设置为“auto”作为设置“ user.name/email ”以向Git引入自己的第一件事。 Now the variable defaults to " auto ". 现在变量默认为“ auto ”。

So you will see colors by default. 所以你会默认看到颜色。


#5楼

Git automatically colors most of its output if you ask it to. 如果你问的话,Git会自动为它的大部分输出着色。 You can get very specific about what you want colored and how; 你可以非常具体地了解你想要的颜色和方式; but to turn on all the default terminal coloring, set color.ui to true: 但要打开所有默认终端着色,请将color.ui设置为true:

git config --global color.ui true

#6楼

Another way is to edit the .gitconfig (create one if not exist), for instance: 另一种方法是编辑.gitconfig (如果不存在则创建一个),例如:

vim ~/.gitconfig

and then add: 然后添加:

[color]
  diff = auto
  status = auto
  branch = auto
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值