Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-log

graph

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.

like image 785
Egor Skriptunoff Avatar asked Nov 18 '16 10:11

Egor Skriptunoff


People also ask

What does git log -- graph do?

The git log graph command creates a graphic overview of how a developer's various development pipelines have branched and merged over time.

How do you show the logs on a git graph?

The --graph flag enables you to view your git log as a graph. To make things things interesting, you can combine this command with --oneline option you learned from above. One of the benefit of using this command is that it enables you to get a overview of how commits have merged and how the git history was created.

What is a git graph?

Git stores history as a graph of snapshots of the entire repository. These snapshots, called commits in Git, can have multiple parents, creating a history that looks like a graph instead of a straight line.

What does -- decorate command do?

The --decorate flag makes git log display all of the references (e.g., branches, tags, etc) that point to each commit. This lets you know that the top commit is also checked out (denoted by HEAD ) and that it is also the tip of the main branch.


1 Answers

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.

like image 94
torek Avatar answered Sep 30 '22 08:09

torek