2012-10-09 36 views
70

我要上色的git状态输出,使:如何着色git-status输出?

untracked files = magenta 
new files = green 
modified files = blue 
deleted files = red 

我也看不到绿色和不分级的文件以蓝色上演文件: screenshot of git-status

我的.gitconfig是设置有以下依据某些搜索:

[color] 
status = auto 

[color "status"] 
added = green 
changed = blue 
untracked = magenta 
deleted = red 
+1

注:git 2.9.1支持属性斜体和罢工。看到我的编辑如下。 – VonC

回答

97

git config doc

color.status.<slot> 

使用自定义颜色进行状态着色。
<slot>是下列之一:

  • header(状态消息的标题文本),
  • addedupdated(其中添加但不提交的文件),
  • changed(其被改变的文件,但没有在索引中添加),
  • untracked(未通过git跟踪的文件),
  • branch(当前分支),或
  • nobranch(显示no分支警告的颜色,默认为红色)。

这些变量的值可以在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.modified

当然,作为commentedelboletaire

记住,使着色输出,如果它以前尚未启用:

git config --global color.ui true 

Shaun Luttin增加:

该命令还可以引用多个参数。这包括来自此列表的两种颜色(前景背景):

正常,黑色,红色,绿色,黄色,蓝色,洋红色,青色和白色;

并且它也包括从该列表中选择一个属性(类型):

粗体,暗淡,UL,眨眼和反向。

那么这将工作:

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)
(在commit 3c5de5cJunio C Hamano -- gitster --合并,2016年7月11日)

这也让 “no-” 为否定属性

使用 “no-bold”,而不是 “nobold” 更容易阅读,更自然打字(对我来说,无论如何,即使我是第一个介绍“无名人”的人)。允许两者都很容易。

+20

记住如果以前没有启用着色输出:'git config --global color.ui true' – elboletaire

+1

@elboletaire好点。我已经将它包含在答案中以提高可见性。 – VonC

+0

谢谢,color.ui是答案。 – Robeezy