简体   繁体   English

Windows命令提示符中不显示Git颜色

[英]Git colors don't display in Windows command prompt

I assume that it's because of the color setting in my config file, but I've tried changing that to no avail. 我认为这是因为我的配置文件中的颜色设置,但我尝试改变它无济于事。 Maybe I'm not doing that right? 也许我不这样做?

Notice that Git Bash shows branch color in green, but on window cl it's not showing at all! 请注意,Git Bash以绿色显示分支颜色,但在窗口cl上它根本不显示!

在此输入图像描述

$ git branch
* add_bower *<~~~ only the asterisk appears on the windows prompt.*
  master

git in cmd should work just fine. cmd中的git应该可以正常工作。 I would check both your gitconfig local and gitconfig global before giving up here. 在放弃之前我会检查你的gitconfig local和gitconfig global。

the first thing I would do is a 我要做的第一件事是

git branch --color

or 要么

git diff --color

you can also use the -c option 你也可以使用-c选项

git -c color.ui=always status

if you see colors then what is likely happening is your local gitconfig is overriding the setting in your global gitconfig 如果您看到颜色,那么可能发生的是您的本地gitconfig覆盖了全局gitconfig中的设置

at that point do a 那时做一个

git config --local --edit

if things say auto or true and you still don't see colors. 如果事情说自动或真实,你仍然看不到颜色。 set the output to always. 将输出设置为always。 I recommend this b\\c it is possible for git to make mistakes and not treat cmd as a terminal 我推荐这个b \\ c git可能会出错,而不是将cmd视为终端

from git-config : 来自git-config

If this is set to always, git-diff(1), git-log(1), and git-show(1) will use color for all patches. 如果将此设置为always,则git-diff(1),git-log(1)和git-show(1)将使用所有色块的颜色。 If it is set to true or auto, those commands will only use color when output is to the terminal. 如果设置为true或auto,则这些命令仅在输出到终端时使用颜色。 Defaults to false. 默认为false。

like so 像这样

[color]
    branch = always
    diff = always
    interactive = always
    status = always
    ui = always

hope this helps! 希望这可以帮助!

I don't think the command prompt will support coloring different parts of the output out of the box. 我不认为命令提示符将支持从输出框中着色输出的不同部分。 You'd probably need some extension or add-on to handle it. 您可能需要一些扩展或附件来处理它。 Have you considered using Powershell ? 你考虑过使用Powershell吗? In addition to the built-in support for the coloring you're looking for, it's also much more versatile and powerful than the normal command prompt. 除了内置的色彩支持之外,它还比普通的命令提示更加通用和强大。 在Powershell中以颜色输出

I'm seeing the exact same problem, only for some command prompts. 我看到完全相同的问题,仅针对一些命令提示。 (By default it works, but when I run my team's "razzle" customization script the output is broken like your screenshot. Oddly, coloring in git log and status works fine; just branch is broken.) (默认情况下它可以工作,但是当我运行我的团队的“razzle”自定义脚本时,输出会像截图一样被破坏。奇怪的是,git log和status中的着色工作正常;只是分支被破坏了。)

I created a new shortcut that launched the same customization script, and the output is fixed for my new shortcut. 我创建了一个新的快捷方式,启动了相同的自定义脚本,并为我的新快捷方式修复了输出。 Very weird. 很奇怪。


If you run git branch --no-color you see the right output, just without color? 如果你运行git branch --no-color你会看到正确的输出,只是没有颜色?

You can run git config --local --add color.branch never to set that as the default for this repo. 您可以运行git config --local --add color.branch never将其设置为此repo的默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM