git - 如何在 .gitconfig 中使用 ANSI 256 色

标签 git colors git-status 256color

我正在尝试为 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/

相关文章:

Android 自定义 ActionBar 颜色?

jquery - 获取滚动条的颜色

git - 描述 Git 符号

git - 如何获取最新的标签名称?

python - 在 Python 脚本中运行 git 命令会导致语法错误

git - 如何卸载 git-for-windows 并在新位置重新安装?

python - Matplotlib 散点图 - ValueError : RGBA sequence should have length 3 or 4

Git:如何查找 origin/master 是否相当于(本地)master?

git - 如何从 git index 获取文件的内容?

git - Heroku 可以在部署时忽略 git 子模块吗?