Is it possible to "colorize" git log messages?

Is it possible to add some instructions (metacharacters?) To git commit messages so that they appear in git log output format?

EDIT: I will be more specific - is it possible to mark several words in a commit message in different colors? I want to insert color marks in a commit message and view it using git log . For example, I would like the Error ID to be displayed in red. Perhaps there is something like this?

+4
source share
6 answers

You can enable color output by setting the git config color.ui to true . The following should work.

 git config --global color.ui true 

You can then define aliases that add color using the --pretty=format:".." option. But I do not think that there are any individual correspondences. I assume that this is what you need in order to color something like an error identifier. You can, however, divulge commit elements such as hashes, author, branch, etc.

+3
source

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

+1
source

Based on your editing, it seems like you're looking for a way to add formatting to a commit log message. I will answer this by stating that commit messages are stored as plain text in Git Objects . So, theoretically, you could write a program to read and format Git Commit objects using advanced text editing to format text, with almost all existing programs limited to using plain text.

In doing so, you can use the --pretty option above, in combination with the smart name of your commits, to highlight error identifiers.

+1
source

You can do it manually, for example. with something like this:

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

Mark lines 20 and 21 of mine . gitconfig for how I set up git log with colors.

These are my two faviorite git that paint the 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
source

The answer that I haven't found yet is that for the color codes to display correctly in git log and git diff you may also need to indicate that by default core.pager used to use less (as in many disto's.) However, less does not direct color codes to the right, unless you also specify less than the -r ( raw ) parameter. So you need to do this:

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

All Articles