如何着色git-status输出?

And*_*ndy 87 git git-config git-status

我想着色git-status输出,以便:

untracked files = magenta
new files = green
modified files = blue
deleted files = red
Run Code Online (Sandbox Code Playgroud)

我反而看到绿色和非分页文件中的分段文件为蓝色: git-status的屏幕截图

我的.gitconfig根据一些搜索设置如下:

[color]
status = auto

[color "status"]
added = green
changed = blue
untracked = magenta
deleted = red
Run Code Online (Sandbox Code Playgroud)

Von*_*onC 117

git config doc:

color.status.<slot>
Run Code Online (Sandbox Code Playgroud)

使用自定义颜色进行状态着色.
<slot>是其中之一:

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

这些变量的值可以指定为color.branch.<slot>.

所以这将有效:

git config color.status.changed blue
git config color.status.untracked magenta
Run Code Online (Sandbox Code Playgroud)

然而:

new files = green
deleted files = red
Run Code Online (Sandbox Code Playgroud)

不可能:您需要选择一种颜色:

  • 如果将它们添加到索引中,它们将选择颜色color.status.added.
  • 如果它们没有添加到索引中,它们将选择颜色或 color.status.modified.

当然,正如elboletaire 评论那样:

如果先前未启用着色输出,请记住启用它:

git config --global color.ui true
Run Code Online (Sandbox Code Playgroud)

Shaun Luttin补充道:

该命令还可以在引号中使用多个参数.这包括此列表中的两种颜色(前景背景):

普通,黑色,红色,绿色,黄色,蓝色,洋红色,青色和白色;

它还包含此列表中的一个属性(样式):

粗体,暗淡,ul,眨眼和反转.

所以这将有效:

git config color.status.changed "blue normal bold"
git config color.status.header "white normal dim"
Run Code Online (Sandbox Code Playgroud)

注意:使用git 2.9.1(2016年7月),输出着色方案学习了两个新属性,斜体罢工,除了现有的粗体,反转等

请参阅Jeff King()提交9dc3515,提交54590a0,提交5621068,提交df8e472,提交ae989a6,提交adb3356,提交0111681(2016年6月23日).(由Junio C Hamano合并- -提交3c5de5c,2016年7月11日)peff
gitster

它还允许" no-"否定属性

使用" no-bold"而不是" nobold"更容易阅读,更自然地输入(对我来说,无论如何,即使我是第一个引入"nobold"的人).允许两者都很容易.

  • 如果以前没有启用着色输出,请记住启用着色输出:`git config --global color.ui true` (27认同)
  • @alper阅读https://unix.stackexchange.com/a/19320/7490,我建议: `git -c color.status=always status -sb --ignore-submodules=dirty | 少-rFX` (4认同)