Skip to main content
  1. Posts/

Better Git log

··275 words·2 mins·
Table of Contents

Some of the settings to make git log better.

Decorate commit
#

The --decorate option will show references to your commit. For example, where your HEAD is, where your master points to etc. To use --decorate by default:

git config --global log.decorate true

Show short commit hash
#

By default, git shows long commit hash for each commit. To show a short commit hash, we can use the --abbrev-commit option. To use --abbrev-commit by default:

git config --global log.abbrevCommit true

Show commit graph
#

To show a graphical representation of commit, which is handy when we have merged commit or multiple branches, we can use --graph option:

git log --graph

Use color and format string for log output
#

We can also combine color and % escaped format string to format the log output. Check here for a list of format strings that you can use for log format. Some of most used format string:

  • %h: the abbreviated commit hash
  • %s: the commit message subject
  • %b: the commit message body
  • %d: ref names, like origin/master, origin/HEAD, tag: v0.8
  • %ci: commit date

Use color to differentiate different part of log message. We can specify a color like this %C(red), %Creset will reset the color. For more details on the color format and which colors to use, check color for git pretty format.

Combining the log format string and color, we can create beautiful log message.

git config format.pretty "%C(magenta)%h%Creset -%C(red)%d%Creset %s %C(green)(%cr) %C(cyan)<%an>%Creset"

After this setup, git-log output will be like what is shown in the title image.

References
#

Related

Git line ending config
·450 words·3 mins
Databricks Cli Usage
·141 words·1 min
File Systems in Databricks
·304 words·2 mins