git log --graph 中的线条颜色是什么意思?

What do line colors in git log --graph mean?

我很好奇 git log --graph 中的线条颜色是什么意思?

是的,我问的是 | / \ 行,它在控制台输出的左边缘连接提交 *

问题 #1
这些颜色有什么隐藏的含义吗?
或者它们是伪随机选择的?

问题 #2
有时重叠(但断开连接)的线具有相同的颜色。
例如,请参见上面屏幕截图中的紫色线条:

是否可以要求 git 明智地选择颜色以避免孤立(没有共同提交)的相同颜色线重叠?
我希望图表更易于阅读。

这些颜色只是为了帮助您将线条与其他线条区分开来。要回答问题 #1,它们不是伪随机分配的,而是 顺序 ,每次 git log --graph 选择一个新的 "column number"。不幸的是,我知道有两个问题。两者都与您的问题 #2 有关。

Here is the full list of colors by name:

    GIT_COLOR_RED,
    GIT_COLOR_GREEN,
    GIT_COLOR_YELLOW,
    GIT_COLOR_BLUE,
    GIT_COLOR_MAGENTA,
    GIT_COLOR_CYAN,
    GIT_COLOR_BOLD_RED,
    GIT_COLOR_BOLD_GREEN,
    GIT_COLOR_BOLD_YELLOW,
    GIT_COLOR_BOLD_BLUE,
    GIT_COLOR_BOLD_MAGENTA,
    GIT_COLOR_BOLD_CYAN,

从视觉上看,其中许多颜色 "look the same"(或足够相似以至于难以区分)。特别是,我发现 "bold" 看起来太像 "regular" 除非在 "bold" 中打印了相当多的字母,即我的 Mac 终端字体的 "bold" 只是没有比它的标准重量更大胆。例如,这使得 Git 存储库中 git log --graph --decorate --oneline --all 运行 的图表中的许多行在视觉上过于相似。

Edit:从 Git 2.12 开始,使用新的 log.graphColors 配置条目,现在可以修复(或变通)。这是一个逗号分隔的颜色名称或颜色编号列表(参见 the git config documentation entry for "color" in the Values section)。

其次,"column number" 目前实际上不是行 的 列号。相反,它是提交 列号。线条颜色从那个提交到它上面的提交 up。图像快照中的所有洋红色行都转到列 #0 中打印的提交:a55fd8d3c1494a 都在 "column 0" 中。 (它们都是合并提交,因此它们合并了传入行。)

Is it possible to ask git to choose colors wisely to avoid isolated (not having common commit) same color lines to overlap?

不过,您始终可以克隆 Git repository for Git and write new code. I will note that the existing graph.c 将近 1400 行。

在此提交中 73c727d69f47572bf7f21fa31831f9a3fdad944c ("log --graph: customize the graph lines with config log.graphColors", 2017-01-19), it's possible to choose the colors with the log.graphColors config

Even with standard terminal, if your background color is neither black or white, then the graph line may match your background and become hidden. You can exclude your background color (or simply the colors you hate) with this.

我使用 Git Bash 并且出于上述原因我排除了 GIT_COLOR_BLUE 颜色。

我可以使用任何十六进制颜色代码(至少在 Git Bash 上)。下面的配置设置只使用三种颜色。

[log]
    graphColors = "#ffffff",red,green

请注意,在章鱼合并的情况下,这些颜色 是准确的,这意味着合并提交 多于 2 个父项。

章鱼合并的

"git log --graph" 有时颜色不正确,这在 Git 2.24(2019 年第四季度)中进行了演示和记录,但尚未修复。

commit 11c21f2, commit 25eb905, commit 63be8c8, commit a7a5590, commit 94ba151 (04 Oct 2019) by Denton Liu (Denton-L)
(由 Junio C Hamano -- gitster -- in commit 5b900fb 合并,2019 年 10 月 15 日)

t4214: demonstrate octopus graph coloring failure

Signed-off-by: Denton Liu

The graph coloring logic for octopus merges currently has a bug. This can be seen git.git with 74c7cfa875 (Merge of http://members.cox.net/junkio/git-jc.git, 2005-05-05), whose second child is 211232bae6 (Octopus merge of the following five patches., 2005-05-05).

If one runs

git log --graph 74c7cfa875

one can see that the octopus merge is colored incorrectly.
In particular, the horizontal dashes are off by one color. Each horizontal dash should be the color of the line to their bottom-right. Instead, they are currently the color of the line to their bottom.