我正在尝试为 git 状态设置自定义颜色,如 here 所述
虽然使用预定义的颜色名称有效:
[color "status"]
changed = yellow normal
使用 ANSI 256 颜色代码不起作用:
[color "status"]
changed = "\033[38;5;214m" normal
我收到错误:
fatal: bad config line 31 in file .gitconfig
我尝试过使用十六进制代码,但这也不起作用:
[color "status"]
changed = "#d70000" normal
我怀疑 #
被解释为注释。
我的git版本是2.20.1
最佳答案
如果您想使用 256 色代码,可以使用 0 到 255 之间的正常数字。例如,在我的 .gitconfig
中,有以下条目:
[color.diff]
new = 34
old = 203
您不想将实际的转义序列放入文件中。 Git 知道如何获取数值并发出正确的 ANSI 转义序列。但是,它不处理特定于终端的功能或使用 terminfo,因此如果您的终端不支持标准 ANSI 序列,那么它将无法与 Git 一起使用。
关于git - 如何在 .gitconfig 中使用 ANSI 256 色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69112016/