4

When I run the command git log --graph --oneline --all --decorate I see branch and tag names in color (I think since I set color.ui to auto). I like this, however a couple of the colors are very hard to read, especially yellow, since I have a white background.

I would like to change this, and I found (in the Git book under color.* here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) that you can change settings under color.* to further customize Git's colors. However, none of the 4 subsettings (branch, diff, interactive, and status) seem to affect the colors used by git log for branch and tag names. Is it possible to change these colors, and if so how?

Stephen
  • 8,508
  • 12
  • 56
  • 96

2 Answers2

13

In my config I have color.diff.commit set to yellow. I just tested command

git -c color.diff.commit=green log

and the color of commit is surely changed to green. See my .gitconfig and (separately included) colors (also in a personal git repo).

Upd. For branch and tags colors you need to set color.decorate.branch and color.decorate.tag. Example (from my "light_bg" file):

[color "decorate"]
    HEAD = cyan
    branch = green
    tag = blue bold
phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    I'm talking about the color of the log output. I think you're talking about the color of commit messages which is different, though I don't know what is meant by "log" at the end of your command. – Stephen Feb 08 '18 at 22:38
  • My command is `git log` — i.e. exactly the command you want to configure colors for — with an additional config setting. – phd Feb 08 '18 at 22:54
  • Sorry, I see now that my question was very poorly phrased since I didn't indicate that I was trying to change the colors for branch and tag names. I will fix it now. – Stephen Feb 09 '18 at 15:40
  • You need to set `color.decorate.branch` and `color.decorate.tag`. See *update* in the answer. – phd Feb 09 '18 at 15:47
  • color.decorate.tag is exactly what I was looking for. Thanks! – The Godfather Jun 28 '18 at 09:19
4

The git log --graph column colors are configurable through:

log.graphColors

as documented (not very well) in the git config manual.

The default set is red, green, yellow, blue, magenta, cyan, bold red, bold green, bold yellow, bold blue, bold magenta, bold cyan.

The decoration names (tag: tagname, HEAD, branch names, and so on) are colored according to color.decorate.slot, where slot is one of branch, remoteBranch, tag, stash, or HEAD. (This control setting was new in Git 1.7.2, so if you have Git 1.7.1 or older you don't have it.)

There are many more control knobs: search the git config documentation for the word color.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks. So I should set graphColors to a set? How do I do that? – Stephen Feb 08 '18 at 22:35
  • Follow the documentation link and search for `graphColors`; you will find this text: "A list of colors, separated by commas, that can be used to draw history lines in `git log --graph`." So, list the colors you want used, separated by commas. (That's why I spelled out the default color set the way I did. Maybe the edit I just made makes it stand out better?) – torek Feb 08 '18 at 22:59
  • Sorry, I am not sure why I glossed over the "separated by commas." Anyway, I tried it but it didn't have an effect. To clarify, I'm trying to change the colors used to display branch and tag names next to the logs. It looks like this setting only changes "history lines" - which is strange because those seem to only be black anyway. – Stephen Feb 09 '18 at 15:37
  • 2
    My command was `git config --global log.graphColors "red,green,blue,magenta,cyan,bold red,bold green,bold blue,bold magenta,bold cyan"` – Stephen Feb 09 '18 at 15:39
  • Sorry, I see now that my question was very poorly phrased since I didn't indicate that I was trying to change the colors for branch and tag names. I will fix it now. – Stephen Feb 09 '18 at 15:40
  • Incidentally, you can also run `git config --global --edit` to bring up your configured editor on your configuration. I like to use this myself for making minor tweaks to existing configurations (well, admittedly I just run `vim ~/.gitconfig` :-) ). – torek Feb 09 '18 at 15:57
  • Thanks, this works. One minor thing - it seems like HEAD defaults to a light blue that isn't possible to set with the available colors. Do you know how to set that? – Stephen Feb 12 '18 at 21:50
  • 1
    The built in default for `HEAD` is `bold cyan`, which should match that particular light blue. Note that in modern Git you can also use a numeric color (0-255) and even a 24-bit red/green/blue triple using the `#RRGGBB` syntax (a la HTML; the two characters encode a 256-bit value in hexadecimal). – torek Feb 12 '18 at 22:00
  • From the documentation: > that can be used to draw history lines. This does not answer the question about tags coloring – The Godfather Jun 28 '18 at 09:18
  • @TheGodfather: see the paragraph starting with `The decoration names ...`. (Perhaps I should have put that in at the top, but this answer is pretty short. Also the original question phrasing sounded like he wanted to change the graph line colors.) – torek Jun 28 '18 at 13:17