使用其他应用程序对git中的差异输出进行着色

问题描述:

在使用git时,我想使用 cdiff 为我的差异输出着色。我可以将git命令的输出通过cdiff传递,但我想知道是否有可能不必这样做。

I want to use cdiff to colourize my diff output when using git. I could pass the output from git commands through cdiff, but I'd like to know if it's possible to not have to do this.

具体来说,当我使用 git log -p ,我希望它使用cdiff来使输出着色,当我使用 git commit -p 时,我想要使用cdiff对输出着色。我想告诉git不要自己着色,而是使用这个额外的程序。

Specifically, when I use git log -p, I want it to use cdiff to colourize the output, when I use git commit -p, I want it to use cdiff to colourize the output. I'd like to tell git to not do the colouring itself, and to instead use this extra programme.

我该怎么做?

据我所知,git产生了 ANSI转义代码本身,而没有委托给任何第三方工具:在 git config 会将其转移到外部程序。

例如参见 contrib / completion / git-prompt.sh (在 t / t4026-color.sh )。

From what I can see, git produces its ANSI escape codes itself, without delegating to any third party tool: I don't see an easy way in git config to transfer that to an external program.
See for instance "contrib/completion/git-prompt.sh" (tested in t/t4026-color.sh).

然后Git调用您可以配置的寻呼机,如 git中的ANSI颜色未正确显示

Then Git calls the pager which you can configure as shown in "ANSI color in git is not displayed correctly".