How to colorize git-status output?

拥有回忆 提交于 2019-11-29 19:04:25
VonC

From git config doc:

color.status.<slot>

Use customized color for status colorization.
<slot> is one of:

  • header (the header text of the status message),
  • added or updated (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), or
  • nobranch (the color the no branch warning is shown in, defaulting to red).

The values of these variables may be specified as in 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.

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 adds:

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.

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, italic and strike, in addition to existing bold, reverse, etc.

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)

It also allow "no-" for negating attributes

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!