来自git config doc:
color.status.<slot>
使用自定义颜色进行状态颜色设置。
<slot>
的取值包括以下内容:
header
(状态消息的标题文本)
added
或updated
(已添加但未提交的文件)
changed
(已更改但未添加到索引中的文件)
untracked
(git未跟踪的文件)
branch
(当前分支)
nobranch
(未显示分支警告的颜色,默认为红色)
localBranch
或remoteBranch
(在状态短格式中显示分支和跟踪信息时分别表示本地和远程分支名称)
unmerged
(存在未合并更改的文件)
这些变量的值可以指定为color.branch.<slot>
。
git config color.status.changed blue
git config color.status.untracked magenta
然而:
new files = green
deleted files = red
不可能:您需要选择一种颜色:
- 如果它们被添加到索引中,它们将使用
color.status.added
的颜色。
- 如果它们没有被添加到索引中,它们将使用
color.status.changed
的颜色。
注意:
颜色也可以作为介于0和255之间的数字给出; 这些使用ANSI 256色模式(但并非所有终端都支持此功能)。
请参见
xterm 256 colors中由
Joshua Goldberg在
the comments中注明的这些数字。
Of course, as commented by elboletaire:
Remember to enable coloring output if it has not been enabled previously:
git config --global color.ui true
Shaun Luttin 补充道:
该命令还可以在引号中接受多个参数。其中包括此列表中的两种颜色(前景和背景):
normal、black、red、green、yellow、blue、magenta、cyan 和 white;
还包括此列表中的一个属性(样式):
bold、dim、ul、blink 和 reverse。
因此,这将起作用:
git config color.status.changed "blue normal bold"
git config color.status.header "white normal dim"
注意:自Git 2.9.1(2016年7月)起,输出颜色方案新增了两个属性:
斜体和
删除线,除了现有的加粗、反转等。
查看 commit 9dc3515,commit 54590a0,commit 5621068,commit df8e472,commit ae989a6,commit adb3356,commit 0111681(2016年6月23日)由Jeff King(peff
)提交。
(由Junio C Hamano -- gitster
--在commit 3c5de5c中合并,于2016年7月11日)
它还允许使用"
no-
"来否定属性。
使用"no-bold
"而不是"nobold
"更易于阅读和打字(对我来说更自然),即使我是最初引入"nobold
"的人。很容易同时允许两种写法。