I spent a morning wrestling with git after writing a minor GIMP fix that I wanted to check in. Deceptively simple ideas, like "Check the git log to see the expected format of check-in messages", turned out to be easier said than done.
Part of the problem was git's default colors: colors calculated to be invisible to anyone using a terminal with dark text on a light background. And that sent me down the perilous path of git configuration.
does have a manual page. But it lacks detail: you can't get
from there to knowing what to change so that the first line of commits
git log doesn't show up yellow.
But that's okay, thought I: all I need to do is list the default settings, then change anything that's a light color like yellow to a darker color. Easy, right?
Well, no. It turns out there's no way to get the default settings -- because they aren't part of git's config; they're hardwired into the C code.
But you can find most of them with a seach for GIT_COLOR in the source. The most useful lines are these the ones in diff.c, builtin-branch.c and wt-status.c.
The next step is to translate those C lines to git preferences, something you can put in a .gitconfig. Here's a list of all the colors mentioned in the man page, and their default values -- I used "normal" for grep and interactive where I wasn't sure of the defaults.
[color "diff"] plain = normal meta = bold frag = cyan old = red new = green commit = yellow whitespace = normal red [color "branch"] current = green local = normal remote = red plain = normal [color "status"] header = normal added = red updated = green changed = red untracked = red nobranch = red [color "grep"] match = normal [color "interactive"] prompt = normal header = normal help = normal error = normal
The syntax and colors are fairly clearly explained in the manual: allowable colors are normal, black, red, green, yellow, blue, magenta, cyan and white. After the foreground color, you can optionally list a background color. You can also list an attribute, chosen from bold, dim, ul, blink and reverse -- only one at a time, no combining of attributes.
So if you really wanted to, you could say something like
[color "status"] header = normal blink added = magenta yellow updated = green reverse changed = red bold untracked = blue white nobranch = red white bold
Minimal changes for light backgrounds
What's the minimum you need to get everything readable? On the light grey background I use, I needed to change the yellow, cyan and green entries:
[color "diff"] frag = cyan new = green commit = yellow [color "branch"] current = green [color "status"] updated = green
Disclaimer: I haven't tested all these settings -- because I haven't yet figured out where all of them apply. That's another area where the manual is a bit short on detail ...
[ 22:26 Feb 02, 2010 More programming | permalink to this entry ]