You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改git diff中@@行与末尾标记的颜色?

Git Diff 特定区域颜色修改方案

1. 修改@@ -1 +1, 2 @@行的颜色

Git中对应这个hunk头部的配置项是diff.hunk,你可以通过以下命令设置颜色:

  • 全局生效(所有仓库):
git config --global color.diff.hunk "颜色参数"
  • 仅当前仓库生效:
git config color.diff.hunk "颜色参数"

颜色支持bold(加粗)、reverse(反色)等格式,可与颜色名组合,比如设置为品红色加粗:

git config --global color.diff.hunk "magenta bold"

2. 修改末尾红色方块(尾随空白标记)的颜色

这个标记是Git对尾随空白字符的高亮,对应配置项是diff.whitespace,设置命令:

  • 全局生效:
git config --global color.diff.whitespace "颜色参数"
  • 仅当前仓库生效:
git config color.diff.whitespace "颜色参数"

默认是红色反色,你可以自定义样式,比如改成蓝色加粗:

git config --global color.diff.whitespace "blue bold"

如果习惯直接编辑配置文件,全局配置文件路径为~/.gitconfig,本地仓库配置在.git/config,找到[color "diff"]段落,添加或修改对应条目即可:

[color "diff"]
    hunk = magenta bold
    whitespace = blue bold

内容的提问来源于stack exchange,提问作者User

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 05:33:14