Git colors don't display in Windows command pr

2020-04-11 18:17发布

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!

enter image description here

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

3条回答
干净又极端
2楼-- · 2020-04-11 18:46

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? 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. Output with color in Powershell

查看更多
乱世女痞
3楼-- · 2020-04-11 18:46

git in cmd should work just fine. I would check both your gitconfig local and gitconfig global before giving up here.

the first thing I would do is a

git branch --color

or

git diff --color

you can also use the -c option

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

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. I recommend this b\c it is possible for git to make mistakes and not treat cmd as a terminal

from git-config:

If this is set to always, git-diff(1), git-log(1), and git-show(1) will use color for all patches. If it is set to true or auto, those commands will only use color when output is to the terminal. Defaults to false.

like so

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

hope this helps!

查看更多
时光不老,我们不散
4楼-- · 2020-04-11 18:54

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.)

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?

You can run git config --local --add color.branch never to set that as the default for this repo.

查看更多
登录 后发表回答