为 Mac 终端启用 Git 语法高亮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8131322/
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-10 12:17:42  来源:igfitidea点击:

Enabling Git syntax highlighting for Mac's terminal

gitterminalsyntax-highlighting

提问by thewillcole

I miss the Git syntax highlighting I had on Windows for every "git .*" command like green staged filenames, some bolding, etc.

我想念我在 Windows 上为每个“git .*”命令(如绿色暂存文件名、一些粗体等)突出显示的 Git 语法。

How do I enable Git syntax highlighting for Mac's terminal?

如何为 Mac 的终端启用 Git 语法高亮显示?

回答by rob mayoff

git config --global color.ui auto

回答by DemitryT

For seeing different colors for the diff command, use:

要查看 diff 命令的不同颜色,请使用:

git config --global color.diff true

To globally change colors for most commands, use:

要全局更改大多数命令的颜色,请使用:

git config --global color.ui true

回答by Sam

Colors in Git

Git 中的颜色

Git can color its output to your terminal, which can help you visually parse the output quickly and easily. A number of options can help you set the coloring to your preference.

Git 可以将它的输出着色到您的终端,这可以帮助您快速轻松地直观地解析输出。许多选项可以帮助您根据自己的喜好设置颜色。

color.ui

颜色.ui

Git automatically colors most of its output if you ask it to. You can get very specific about what you want colored and how; but to turn on all the default terminal coloring, set color.ui to true:

如果您要求,Git 会自动为其大部分输出着色。您可以非常具体地了解您想要什么颜色以及如何上色;但要打开所有默认终端着色,请将 color.ui 设置为 true:

$ git config --global color.ui true

When that value is set, Git colors its output if the output goes to a terminal. Other possible settings are false, which never colors the output, and always, which sets colors all the time, even if you're redirecting Git commands to a file or piping them to another command.

设置该值后,如果输出到终端,Git 会为其输出着色。其他可能的设置是 false,它从不为输出着色,并且始终设置颜色,即使您将 Git 命令重定向到一个文件或将它们通过管道传输到另一个命令。

You'll rarely want color.ui = always. In most scenarios, if you want color codes in your redirected output, you can instead pass a --color flag to the Git command to force it to use color codes. The color.ui = true setting is almost always what you'll want to use.

你很少需要 color.ui = always。在大多数情况下,如果您想要重定向输出中的颜色代码,您可以改为将 --color 标志传递给 Git 命令以强制它使用颜色代码。color.ui = true 设置几乎总是你想要使用的。

color.*

If you want to be more specific about which commands are colored and how, Git provides verb-specific coloring settings. Each of these can be set to true, false, or always:

如果您想更具体地了解哪些命令被着色以及如何着色,Git 提供了特定于动词的着色设置。这些中的每一个都可以设置为 true、false 或 always:

color.branch
color.diff
color.interactive
color.status

In addition, each of these has subsettings you can use to set specific colors for parts of the output, if you want to override each color. For example, to set the meta information in your diff output to blue foreground, black background, and bold text, you can run

此外,如果您想覆盖每种颜色,每一个都有子设置,您可以使用这些子设置为输出的部分设置特定颜色。例如,要将 diff 输出中的元信息设置为蓝色前景、黑色背景和粗体文本,您可以运行

$ git config --global color.diff.meta "blue black bold"

You can set the color to any of the following values: normal, black, red, green, yellow, blue, magenta, cyan, or white. If you want an attribute like bold in the previous example, you can choose from bold, dim, ul, blink, and reverse.

您可以将颜色设置为以下任意值:正常、黑色、红色、绿色、黄色、蓝色、品红色、青色或白色。如果您想要上例中的粗体属性,您可以从粗体、暗淡、UL、闪烁和反转中进行选择。

See the git config manpage for all the subsettings you can configure, if you want to do that.

如果您想这样做,请参阅 git config 联机帮助页了解您可以配置的所有子设置。

Reference : http://git-scm.com/book/ch7-1.html

参考:http: //git-scm.com/book/ch7-1.html

回答by Ivan Smirnov

I've used next solution:

我使用了下一个解决方案:

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

Original article

来源文章

回答by Олег Кабанов

git config --global color.diff true
git config --global color.status true
git config --global color.branch true
git config --global color.interactive true

There are 4 settings types available:

有 4 种设置类型可用:

  • false- disabled
  • true- enabled, only in command prompt
  • always- enabled always
  • false- 禁用
  • true- 启用,仅在命令提示符下
  • 始终- 始终启用

回答by Dave Sag

I found this excellent blog postthat explains how to set up your git colours and what the standard colours are. In summary, add the following lines to your ~/gitconfigfile: (Here's mine - pretty eh?)

我发现这篇优秀的博客文章解释了如何设置 git 颜色以及标准颜色是什么。总之,将以下行添加到您的~/gitconfig文件中:(这是我的 - 漂亮吧?

[color]
  ui = auto
[color "branch"]
  current = auto
  remote = white reverse
[color "diff"]
  meta = yellow bold
  frag = magenta bold
  new = green bold
[color "status"]
  added = yellow bold
  changed = green
  untracked = cyan

In modern versions of Git the colour.uisetting is now autoby default.

在现代版本的 Git 中,该colour.ui设置现在auto是默认设置。

You can use the following as colours:

您可以使用以下颜色:

  • normal,
  • black,
  • red,
  • green,
  • yellow,
  • blue,
  • magenta,
  • cyan, and
  • white.
  • normal,
  • black,
  • red,
  • green,
  • yellow,
  • blue,
  • magenta,
  • cyan, 和
  • white.

You can also supply the following optional modifiers:

您还可以提供以下可选修饰符:

  • bold,
  • dim,
  • ul,
  • blink, and
  • reverse.
  • bold,
  • dim,
  • ul,
  • blink, 和
  • reverse.

回答by VonC

Note: starting git1.8.4 (June 2013), you won't have to do anything:

注意:从git1.8.4 (June 2013) 开始您无需执行任何操作

Many tutorials teach users to set "color.ui" to "auto" as the first thing after you set "user.name/email" to introduce yourselves to Git.
Now the variable defaults to "auto".

很多教程教用户设置“color.ui”为“auto”,作为user.name/email对Git的自我介绍后的第一件事。
现在变量默认为 " auto"