如何为 git-status 输出着色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12795790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to colorize git-status output?
提问by Andy
I want to colorize git-status output so that:
我想为 git-status 输出着色,以便:
untracked files = magenta
new files = green
modified files = blue
deleted files = red
I am instead seeing staged files in green and unstaged files in blue:
我看到的是绿色的暂存文件和蓝色的未暂存文件:
My .gitconfig is setup with the following based on some searching:
我的 .gitconfig 是根据一些搜索设置的:
[color]
status = auto
[color "status"]
added = green
changed = blue
untracked = magenta
deleted = red
回答by VonC
From git config doc:
从git 配置文档:
color.status.<slot>
Use customized color for status colorization.
<slot>
is one of:
header
(the header text of the status message),added
orupdated
(files which are added but not committed),changed
(files which are changed but not added in the index),untracked
(files which are not tracked by git),branch
(the current branch),nobranch
(the color the no branch warning is shown in, defaulting to red),localBranch
orremoteBranch
(the local and remote branch names, respectively, when branch and tracking information is displayed in the status short-format),unmerged
(files which have unmerged changes).The values of these variables may be specified as in
color.branch.<slot>
.
使用自定义颜色进行状态着色。
<slot>
是其中之一:
header
(状态消息的标题文本),added
或updated
(添加但未提交的文件),changed
(已更改但未添加到索引中的文件),untracked
(git未跟踪的文件),branch
(当前分支),nobranch
(显示无分支警告的颜色,默认为红色),localBranch
或remoteBranch
(当分支和跟踪信息以状态短格式显示时,分别为本地和远程分支名称),unmerged
(具有未合并更改的文件)。这些变量的值可以在 中指定
color.branch.<slot>
。
So this will work:
所以这将起作用:
git config color.status.changed blue
git config color.status.untracked magenta
However:
然而:
new files = green
deleted files = red
Isn't possible: you need to pick one color:
不可能:您需要选择一种颜色:
- if they are added to the index, they will pick the color for
color.status.added
. - if they aren't added to the index, they will pick the color or
color.status.modified
.
- 如果将它们添加到索引中,它们将为 选择颜色
color.status.added
。 - 如果它们没有被添加到索引中,它们将选择颜色或
color.status.modified
.
Of course, as commentedby elboletaire:
当然,正如elboletaire评论的那样:
Remember to enable coloring output if it has not been enabled previously:
如果之前未启用,请记住启用着色输出:
git config --global color.ui true
Shaun Luttinadds:
肖恩·卢廷补充说:
The command can also take multiple parameters in quotes. This includes two colors (foreground background) from this list:
该命令还可以在引号中使用多个参数。这包括此列表中的两种颜色(前景背景):
normal, black, red, green, yellow, blue, magenta, cyan and white;
正常、黑色、红色、绿色、黄色、蓝色、品红色、青色和白色;
and it also includes one attribute (style) from this list:
它还包括此列表中的一个属性(样式):
bold, dim, ul, blink and reverse.
粗体、暗淡、ul、闪烁和反转。
So this will work:
所以这将起作用:
git config color.status.changed "blue normal bold"
git config color.status.header "white normal dim"
Note: with git 2.9.1 (July 2016), The output coloring scheme learned two new attributes, italicand strike, in addition to existing bold, reverse, etc.
注意:在 git 2.9.1(2016 年 7 月)中,输出着色方案学习了两个新属性,斜体和罢工, 除了现有的粗体、反向等。
See commit 9dc3515, commit 54590a0, commit 5621068, commit df8e472, commit ae989a6, commit adb3356, commit 0111681(23 Jun 2016) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
--in commit 3c5de5c, 11 Jul 2016)
请参阅Jeff King ( ) 的commit 9dc3515、commit 54590a0、commit 5621068、commit df8e472、commit ae989a6、commit adb3356、commit 0111681(2016 年 6 月 23 日)。(由Junio C Hamano合并-- --in commit 3c5de5c,2016 年 7 月 11 日)peff
gitster
It also allow "no-
" for negating attributes
它还允许“ no-
”否定属性
Using "
no-bold
" rather than "nobold
" is easier to read and more natural to type (to me, anyway, even though I was the person who introduced "nobold" in the first place). It's easy to allow both.
使用“
no-bold
”而不是“nobold
”更容易阅读并且打字更自然(对我来说,无论如何,即使我是首先介绍“nobold”的人)。允许两者都很容易。