Is it possible to 'colorize' git log messages?

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?

Answers


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.


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


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.


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

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

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


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'

Need Your Help

How to get x and y coordinates of image inside an imageview in android?

android image imageview coordinates

I'm stuck in this problem. I have an imageView and I would like to get a position of my touch only inside the image. When I touch out of image I must display x=0 and y=0. In this app I must know r...

WebView wont copy the text in Windows 10 mobile

webview copy-paste windows-10-mobile

I have a Windows 8.1 application which I am trying to run on Windows 10 mobile. I have a control which renders html data using Windows.UI.Xaml.Controls.WebView However when I tap on some text on the