在 Posh-Git 中更改“git status”输出颜色

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

Changing "git status" output colors in Posh-Git

gitpowershellwindows-7posh-git

提问by NightShovel

In Posh-Git, when I run "git status" in a repository, the colors for changes and untracked files are dark red, when I have tried to configure them to be "normal" red. I want to do this because I have a console with a dark background, so dark red is difficult to read.

Posh-Git 中,当我在存储库中运行“git status”时,更改和未跟踪文件的颜色为深红色,当我尝试将它们配置为“正常”红色时。我想这样做是因为我有一个带有深色背景的控制台,所以深红色很难阅读。

I searched around, and there seem to be two configuration changes which I needed to make:

我四处搜索,似乎需要进行两项配置更改:

  1. Change "WorkingForegroundColor" and "UntrackedForegroundColor" from "DarkRed" to "Red" in $GitPromptSettings.

  2. Change "color.status.changed" and "color.status.untracked" to red in git config.

  1. 在 $GitPromptSettings 中将“WorkingForegroundColor”和“UntrackedForegroundColor”从“DarkRed”更改为“Red”。

  2. 在 git config 中将“color.status.changed”和“color.status.untracked”更改为红色。

From my reading, that's all I should need to do, and yet the results of "git status" remain dark red.

从我的阅读来看,这就是我应该做的所有事情,但“git status”的结果仍然是深红色。

Here's a summary, to prove I set them as I claimed, and maybe someone can spot the error:

这是一个摘要,以证明我按照我的要求设置了它们,也许有人可以发现错误:

screenshot

截屏

采纳答案by BartekB

There is only one way to change DarkRed to Red here: modify color scheme of console window itself. As far as I know git will pick "first" red on the list (that happens to be dark...). So just increase R value for it.

这里只有一种方法可以将 DarkRed 更改为 Red:修改控制台窗口本身的配色方案。据我所知,git 会在列表中选择“第一个”红色(恰好是黑色的......)。所以只需增加它的R值。

You can do it directly on window (Properties -> Colors) or in registry. Prompt is different story: it uses PS color names, where Red = Red, not DarkRed...

您可以直接在窗口(属性 -> 颜色)或注册表中执行此操作。提示是不同的故事:它使用 PS 颜色名称,其中红色 = 红色,而不是暗红色...

回答by WarrenB

The output of git statusis controlled by your .gitconfig file. The default for changedand untrackedfiles is a dim Redbut you likely want Red Boldwhich is the bright (default) red you have in the prompt.

的输出git status由您的 .gitconfig 文件控制。changeduntracked文件的默认值是暗色,Red但您可能想要提示Red Bold中的亮(默认)红色。

Add the following to your .gitconfig file:

将以下内容添加到您的 .gitconfig 文件中:

[color]
    ui = true
[color "status"]
    changed = red bold
    untracked = red bold
    added = green bold

For anyone else referencing this in the future, the accepted colours are normal, black, red, green, yellow, blue, magenta, cyan, and whiteas well a single optional modifier bold, dim, ul, blink, or reverse. If two colours are given the first is the foreground, and the second is the background.

对于将来引用此内容的任何其他人,可接受的颜色是normal, black, red, green, yellow, blue, magenta, cyan,white以及一个可选的修饰符bold, dim, ul, blink, 或reverse。如果给出两种颜色,第一种是前景,第二种是背景。

回答by Thomas Svensen

To change the color of the listed untracked and modified files to the more readable yellow color, you can add this to your ~/.gitconfig file:

要将列出的未跟踪和修改文件的颜色更改为更易读的黄色,您可以将其添加到您的 ~/.gitconfig 文件中:

[color "status"]
    untracked = bold yellow
    changed = bold yellow

Also updating you GitPrompt.ps1 to show untracked as yellow is then probably a good idea:

同时更新您的 GitPrompt.ps1 以显示未跟踪为黄色可能是一个好主意:

    UntrackedForegroundColor  = [ConsoleColor]::Yellow
    WorkingForegroundColor    = [ConsoleColor]::Yellow

Edit: GitPrompt.ps1 is found in the PowerShell posh-git folder.

编辑:GitPrompt.ps1 位于 PowerShell posh-git 文件夹中。

回答by Ade Miller

You can change these by modifying the source of the GitPrompt.ps1 file in the PowerShell posh-git module folder. I had the same issue and just removed the 'Dark' in the colors defined around line 30 in this file:

您可以通过修改 PowerShell posh-git 模块文件夹中的 GitPrompt.ps1 文件的源来更改这些。我遇到了同样的问题,只是删除了此文件中第 30 行周围定义的颜色中的“暗”:

BeforeIndexForegroundColor= [ConsoleColor]::**Green**
BeforeIndexBackgroundColor= $Host.UI.RawUI.BackgroundColor

IndexForegroundColor      = [ConsoleColor]::**Green**
IndexBackgroundColor      = $Host.UI.RawUI.BackgroundColor

WorkingForegroundColor    = [ConsoleColor]::**Red**
WorkingBackgroundColor    = $Host.UI.RawUI.BackgroundColor

UntrackedText             = ' !'
UntrackedForegroundColor  = [ConsoleColor]::**Red**

This list of Powershell colorsis also useful.

这个Powershell 颜色列表也很有用。

回答by Luigi Lopez

In addition of @WarrenB answer. To change the color of status andthe color of the git diff (of new lines and removed lines) you have to have this in your .git/config file:

除了@WarrenB 答案。要改变现状的颜色的git的差异的颜色(新线和删除的行),你必须有这个在你的.git / config文件:

[color]
ui = true
[color "status"]
changed = red bold
untracked = red bold
added = green bold
[color "diff"]
old = red bold
new = green bold

The "diff" option enables you the bright (bold) red and green colors. Reference: https://git-scm.com/docs/git-config#git-config-colordiff

“diff”选项使您可以使用明亮(粗体)的红色和绿色。参考:https: //git-scm.com/docs/git-config#git-config-colordiff