What do line colors in git log --graph mean?
Asked Answered
S

3

36

I'm curious what do line colors mean in git log --graph?

Yes, I'm asking about lines | / \ which connect commits * at the left edge of console output.

part of git log --graph output

Question #1
Do these colors have some hidden meaning?
Or do they are pseudo-randomly chosen?

Question #2
Sometimes overlapped (but disconnected) lines have the same color.
For example, see at the purple lines on the screenshot above:

  • first line from a55 to e1c
  • second line from 3c1 to 043

Is it possible to ask git to choose colors wisely to avoid isolated (not having common commit) same color lines to overlap?
I want the graph to be more easily readable.

Sensitivity answered 18/11, 2016 at 10:47 Comment(2)
My guess would be that a commit in a branch is identical to a commit in the other branch due to a merge whereas different colors signify separate commits.Kurys
What do the colors mean? Nothing. They're just a mechanism to make it easier to visually distinguish between different sequences of commits...Reporter
S
16

The colors are merely meant to help you view the lines as distinct from other lines. To answer question #1, they are assigned not pseudo-randomly, but rather sequentially, each time git log --graph picks a new "column number". Unfortunately there are two issues I know of. Both tie into your question #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,

Visually, many of these colors "look the same" (or similar enough to be kind of indistinguishable). In particular, I find that the "bold" ones look too much like the "regular" ones unless there are quite a few letters printed in "bold", i.e., my Mac Terminal font's "bold" is just not that much bold-er than its standard-weight. This makes many lines overly visually similar in the graph for git log --graph --decorate --oneline --all run on the Git repository for Git, for instance.

Edit: this is now fixable (or work-around-able), as of Git 2.12, using the new log.graphColors configuration entry. This is a comma separated list of color names or color numbers (see the git config documentation entry for "color" in the Values section).

Second, the "column number" is, currently, not actually the column number of the line. Instead, it's the column number of the commit. The line color goes up from that commit, to the commit above it. All the magenta lines in your image snapshot go to commits printed in column #0: both a55fd8d and 3c1494a are in "column 0". (They are both merge commits so they consolidate incoming lines.)

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

You can always clone the Git repository for Git and write new code. I will note that the existing graph.c is nearly 1400 lines long, though.

Spiritless answered 18/11, 2016 at 19:16 Comment(3)
Thanks. As I see now, the coloring algorithm currently implemented in git is good enough for several parallel lines of commits ("one branch for each developer") and is not good for "a lot of developers on a single branch" way of using git repo (which is a usual case for many organizations, AFAIK).Sensitivity
@torek, if you like you could edit your answer to mention to use the log.graphColors config (you can use my answer below if you want) to choose colors. The OP did not ask for this but this setting solves readability issues for most people.Lietman
@hIpPy: interesting; this is new in Git 2.12.Spiritless
L
6

In this commit 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.

I use Git Bash and I exclude GIT_COLOR_BLUE color for above reason.

I can use any hex color codes (at least on Git Bash). Below config setting uses only three colors.

[log]
    graphColors = "#ffffff",red,green
Lietman answered 16/5, 2017 at 5:27 Comment(0)
N
1

Note that those colors would not be accurate in case of an octopus merge, meaning a merge commit with more than 2 parents.

"git log --graph" for an octopus merge is sometimes colored incorrectly, which is demonstrated and documented in Git 2.24 (Q4 2019), but not yet fixed.

See commit 11c21f2, commit 25eb905, commit 63be8c8, commit a7a5590, commit 94ba151 (04 Oct 2019) by Denton Liu (Denton-L).
(Merged by Junio C Hamano -- gitster -- in commit 5b900fb, 15 Oct 2019)

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.

Neisse answered 21/10, 2019 at 16:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.