在 Posh-Git 中,当我在存储库中运行“git status”时,当我尝试将它们配置为“正常”红色时,更改和未跟踪文件的颜色为深红色。我想这样做是因为我有一个深色背景的控制台,因此深红色很难阅读。
我四处搜索,似乎有两个配置需要更改:
在 $GitPromptSettings 中将“WorkingForegroundColor”和“UntrackedForegroundColor”从“DarkRed”更改为“Red”。
在 git config 中将“color.status.changed”和“color.status.untracked”更改为红色。
从我的阅读来看,这就是我应该做的,但“git status”的结果仍然是深红色。
这里有一个总结,以证明我按照我的说法设置了它们,也许有人可以发现错误:
git status
的输出由 .gitconfig 文件控制。 changed
和 untracked
文件的默认设置是暗淡的 Red
,但您可能需要 Red Bold
,它是提示中的明亮(默认)红色。
将以下内容添加到您的 .gitconfig 文件中:
[color]
ui = true
[color "status"]
changed = red bold
untracked = red bold
added = green bold
对于将来引用此内容的其他人,可接受的颜色为
normal
、black
、red
、green
、yellow
、blue
、magenta
、cyan
和 white
》以及单个可选修饰符 bold
、dim
、ul
、blink
或 reverse
。如果给出两种颜色,第一种颜色是前景,第二种颜色是背景。
这里将 DarkRed 更改为 Red 只有一种方法:修改控制台窗口本身的配色方案。据我所知,git 会选择列表中的“第一个”红色(恰好是黑色的......)。所以只要增加R值就可以了。
您可以直接在窗口(属性 -> 颜色)或注册表中执行此操作。提示是不同的故事:它使用 PS 颜色名称,其中 Red = Red,而不是 DarkRed...
要将列出的未跟踪和已修改文件的颜色更改为更易读的黄色,您可以将其添加到 ~/.gitconfig 文件中:
[color "status"]
untracked = bold yellow
changed = bold yellow
同时更新 GitPrompt.ps1 以将未跟踪显示为黄色,这可能是一个好主意:
UntrackedForegroundColor = [ConsoleColor]::Yellow
WorkingForegroundColor = [ConsoleColor]::Yellow
编辑:GitPrompt.ps1 可在 PowerShell posh-git 文件夹中找到。
除了@WarrenB 的回答。要更改状态的颜色和 git diff 的颜色(新行和删除的行),您必须将其包含在 .git/config 文件中:
[color]
ui = true
[color "status"]
changed = red bold
untracked = red bold
added = green bold
[color "diff"]
old = red bold
new = green bold
“差异”选项使您能够获得明亮(粗体)的红色和绿色。参考:https://git-scm.com/docs/git-config#git-config-colordiff
您可以通过修改 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**
此 Powershell 颜色 列表也很有用。