4

Is it possible to add some kind of instructions (metasymbols?) to git commit messages, so they will appear colorized in git log output?

EDIT: I will be more specific — is it possible to mark several words in commit message in different color? I want to embed color marks into commit message and review it via git log. For instance I would like to have Bug ID appear in red. It is possible to have something like this?

2
  • 1
    possible duplicate of Color in git-log Jul 16, 2012 at 11:38
  • 1
    @Christian.K, I believe this is not exactly what I'm looking for. I've extended my question description to become more clear about my point.
    – shytikov
    Jul 16, 2012 at 11:45

6 Answers 6

3

You can turn on colourised output by setting the git config option color.ui to true. The following should work.

git config --global color.ui true

Then you can define aliases which adds colours using the --pretty=format:".." option. But I don't think there is any kind of custom matching. I guess that is what you would need to colourise something like bug ID. You can however colourise commit elements like hashes, author, branch, etc.

2

Based on your edit, it appears that you're looking for a way to add formatting to the commit log message itself. I'll answer this by stating that commit messages are stored as plain text within Git Objects. So, theoretically, you could write a program to read and format Git Commit objects using rich text editing, allowing for formatted text, with almost all existing programs you're limited to using plain text.

That being said, you can use the --pretty option mentioned above in combination with intelligent naming of your commits to make bug IDs stand out.

1

git log can take the argument --pretty, which allows you to specify a format string in which you can also specify the color of arguments. You can then alias that to a new shell command. See PRETTY FORMAT here

1

Check out lines 20 and 21 of my .gitconfig for how I customized git log with colors.

These are my two faviorite git alias that colorize git log.

lg1 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative

lg = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' --abbrev-commit

0

You could do it manually, e.g. with something like this:

git log --color=always | grep --color=always -C1000 BUG- | less -R
0

An answer I haven't found here yet, is that in order to get color codes appear properly in git log and git diff, you might also need to specify that the default core.pager is set to use less (as in many disto's.) However, less does not channel the color codes right unless you also give less the -r (raw) option. So you need to do this:

git config --global color.ui true
git config --global core.pager 'less -r'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.