我最近发现Windows上的git
控制台是有颜色的,例如添加绿色,删除红色等。如何使我的git
控制台也有这样的颜色呢?
为了安装它,我使用了以下命令:$ sudo apt-get install git-core
我最近发现Windows上的git
控制台是有颜色的,例如添加绿色,删除红色等。如何使我的git
控制台也有这样的颜色呢?
为了安装它,我使用了以下命令:$ sudo apt-get install git-core
正如 @VonC所指出的那样,自从Git 1.8.4版本以来,color.ui
默认为auto
来自Unix&Linux Stackexchange的问题如何给git命令的输出添加颜色?和@Evgeny的回答:
git config --global color.ui auto
color.ui
是一个元配置,它包含了所有可用于git
命令的各种color.*
配置。这在git help config
中有详细解释。
因此,基本上它比单独设置不同的color.*
设置更容易且更具未来性。
git config
文档中有关于此的深入解释:
color.ui
:此变量确定类似于color.diff
和color.grep
的变量的默认值,这些变量控制每个命令族使用颜色的情况。随着更多的命令学习配置来设置--color
选项的默认值,其范围将扩展。如果您希望所有不适用于机器消费的输出都使用颜色,请将其设置为always
;如果您希望这种输出在写入终端时使用颜色,则将其设置为true
或auto
;如果您希望git命令不使用颜色,除非通过其他配置或--color
选项明确启用它们,则将其设置为false
或never
。auto
就足够了。 - Joel Purraui = auto
条目添加到用户的~/.gitconfig
文件中的[color]
部分。 - Andris举个例子,查看https://web.archive.org/web/20080506194329/http://www.arthurkoziel.com/2008/05/02/git-configuration/。
有趣的部分是
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
color.ui auto
无效,但这个方法有效。谢谢。 - Matt K将下面的代码添加到你的 .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
如果你要求,Git会自动为其大多数输出着色。你可以非常具体地指定需要着色的内容以及如何进行着色;但是要打开所有默认终端配色方案,请将 color.ui 设置为 true:
git config --global color.ui true
无论是在Ubuntu或者其他平台(是的,包括Windows!)上,从git1.8.4开始,这个版本于2013-08-23发布, 你不需要做任何事情:
许多教程都会教用户将“color.ui”设置为“auto”,作为设置“
user.name/email
”之后引入自己到Git中的第一件事。 现在该变量默认为“auto
”。
因此,您将默认看到颜色。
git config --global color.ui auto
。我的Mac也是如此,唯一默认为auto
的是我在Windows PC上使用的Git Bash。 - sargas改善Windows 10上Git“分支类型”颜色:
显示命令 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控制台中,dim
选项(参见底部的文档链接)没有任何效果,而bold
选项与bright*颜色具有相同的效果。现在回想一下所示例子中的配置语法:
git config <config-type> color.branch.<slot> "<fg> <bg>"
<config-type>
通常是--system
或--global
。如果省略,则指定的颜色仅应用于当前库。使用刚刚详细介绍的颜色名称,您可以为特定的分支类型设置前景<fg>
和背景<bg>
颜色,其中<slot>
是以下之一:
current
(当前分支)local
(本地分支)remote
(refs/remotes/中的远程跟踪分支)upstream
(上游跟踪分支)plain
git config -l --show-origin
请注意还有一组与日志输出颜色有关的配置选项(此处不讨论):
git config --system color.decorate.(branch|remoteBranch|tag|stash|HEAD|grafted) <color>
~/.gitconfig
文件中,只需添加以下内容即可:[color]
ui = auto
另一种方式是编辑.gitconfig
文件(如果不存在则创建),例如:
vim ~/.gitconfig
[color]
diff = auto
status = auto
branch = auto
[color] ui = auto
就足够了。 - Chackogit config --global color.ui true
git config --global color.ui false
git config --global color.ui auto
您可以从这里选择所需的命令。
在此处--global是可选项,可以为系统中的每个存储库应用操作。如果您只想为当前存储库应用着色,则可以执行以下操作 -
git config color.ui true
如果您不满意默认设置,可以使用ANSI转义码来帮助您设置颜色,如果您想修改某些文本,可以编写bash来帮助您。请参见下面的示例:
# .gitconfig
[alias]
st-color = "!f() { \
echo -n -e '\\033[38;2;255;0;01m\\033[4m' ;\
git status -s | grep ' D' | \
sed -e 's/^ ./DELETE:/' ; \
echo -n -e '\\033[m' ;\
\
echo -n -e '\\033[48;2;128;128;128m' ;\
echo -n -e '\\033[38;2;0;255;01m' ;\
git status -s | grep ' [AM]' | \
sed -e 's/^ ./NEW OR MODIFY:/' ; \
echo -n -e '\\033[m' ;\
\
echo -n -e '\\033[38;2;255;0;255m' ;\
echo Rename ;\
git status -s | grep 'R ' | \
sed -e 's/^..//' ; \
echo -n -e '\\033[m' ;\
}; f"
you can write the long script on .gitconfig
use the syntax as below:
[alias]
your-cmd = !f() { \
\
}; f"
echo -n -e
(see more echo)
\\033[38;2;255;0;0m\\033[4m
(see more SGR parameters)
\\033[38;2;255;0;0m
: 38 mean fore color. 255;0;0 = Red | r;g;b\\033[4m
: underlinegrep
: The grep command is used to search text.
sed -e 's/be_replace_string/new_string/'
replace string to new string.