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

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


当前回答

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

许多教程教用户设置“颜色”。将“user.name/email”设置为“auto”后的第一件事,用于向Git介绍自己。现在该变量默认为"auto"。

所以默认情况下你会看到颜色。

其他回答

例如,参见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

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

vim ~/.gitconfig

然后加上:

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

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

[color]
  ui = auto

它负责所有的git命令。

改进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