本文翻译自: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 正如指出的@VonC , color.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 variouscolor.*
configurations available withgit
commands.color.ui
是一个元配置,包含git
命令可用的所有各种color.*
配置。 This is explained in-depth ingit 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 ascolor.diff
andcolor.grep
that control the use of color per command family.color.ui
:此变量确定控制每个命令族颜色使用的变量(如color.diff
和color.grep
的默认值。 Its scope will expand as more commands learn configuration to set a default for the--color
option. 随着更多命令学习配置以设置--color
选项的默认值,其范围将扩展。 Set it toalways
if you want all output not intended for machine consumption to use color, totrue
orauto
if you want such output to use color when written to the terminal, or tofalse
ornever
if you prefer git commands not to use color unless enabled explicitly with some other configuration or the--color
option. 将其设置为always
,如果你想不用于机器消耗所有输出使用的颜色,以true
或auto
,如果你想这样的输出使用的颜色,当写入到终端,或false
或never
如果你喜欢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