bash 为什么 git 颜色不显示在 iTerm2 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7424037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:01:52  来源:igfitidea点击:

Why don't git colors show up in iTerm2

gitbashiterm

提问by Robert Ross

So I have my gitconfig setup to do colors. In Terminal it works great, looks fine.

所以我有我的 gitconfig 设置来做颜色。在终端中它运行良好,看起来不错。

In iTerm2, however, the colors don't appear for my gitconfig at all unless I set the reverse property for git. Then they appear but who likes reversed colors anyways?

但是,在 iTerm2 中,除非我为 git 设置了 reverse 属性,否则我的 gitconfig 根本不会出现颜色。然后他们出现了,但谁喜欢颠倒的颜色呢?

Why does this happen and how can I fix it?

为什么会发生这种情况,我该如何解决?

回答by Matt

You should check that iTerm is setting the TERM variable correctly. On my system, I see:

您应该检查 iTerm 是否正确设置了 TERM 变量。在我的系统上,我看到:

echo $TERM
xterm-256color

And have working colours in git. This is set according to the 'Report Terminal Type' property in iTerm's preferences.

并在 git 中使用工作颜色。这是根据 iTerm 首选项中的“报告终端类型”属性设置的。

here's a screenshot of iTerm 2's preferences

这是 iTerm 2 首选项的屏幕截图

You should also check the Colors tab, and ensure the contrast slider isn't all the way to the right.

您还应该检查颜色选项卡,并确保对比度滑块没有一直向右。

回答by FlintZA

In my case I had coloured output from other terminal applications in iTerm, just not git. For anyone still looking to solve this, what did it for me was the solution from http://buildamodule.com/forum/post/iterm-git-ui-colors.

就我而言,我在 iTerm 中从其他终端应用程序中获得了彩色输出,而不是 git。对于仍然希望解决此问题的任何人,它对我来说是来自http://buildamodule.com/forum/post/iterm-git-ui-colors的解决方案。

Modify your global git config as follows:

修改你的全局 git 配置如下:

git config --global color.ui true

git config --global color.ui true

回答by dajobe

I found an answer to this via http://code.google.com/p/iterm2/issues/detail?id=1639that works for me.

我通过http://code.google.com/p/iterm2/issues/detail?id=1639找到了对我有用的答案。

"The solution is to add this to your ~/.gitconfig"

“解决方案是将其添加到您的~/.gitconfig

[core]
    pager = less -R