gpt4 book ai didi

git - 如何着色 git-status 输出?

转载 作者:IT王子 更新时间:2023-10-29 01:25:58 27 4
gpt4 key购买 nike

我想为 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

最佳答案

来自 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),
  • nobranch (the color the no branch warning is shown in, defaulting to red),
  • localBranch or remoteBranch (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>.

所以这会起作用:

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 ”,如 the commentsJoshua Goldberg 中所述。


当然,作为 commentedelboletaire :

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 and white;

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

bold, dim, ul, blink and reverse.

所以这会起作用:

git config color.status.changed "blue normal bold"
git config color.status.header "white normal dim"

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

参见 commit 9dc3515commit 54590a0commit 5621068commit df8e472commit ae989a6commit adb3356commit 0111681(2016 年 6 月 23 日),作者 Jeff King ( peff )
(由 Junio C Hamano -- gitster -- merge 到 commit 3c5de5c ,2016 年 7 月 11 日)

它也允许“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.

关于git - 如何着色 git-status 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795790/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com