git log --pretty=format:<format_string>

Show commit history with a fully customized output format.

This command displays the commit history while letting you control exactly which commit fields are shown and how they are formatted, which is useful when you want concise, script-friendly, or visually tailored logs instead of the default verbose view.

It uses git log to list commits, and the --pretty flag switches the output style from the default to a custom one; when used as --pretty=format:<format_string> (or equivalently --pretty="format:<format_string>"), it tells Git to render each commit using the placeholders you specify in <format_string> (for example, %h for abbreviated hash, %an for author name, %s for subject), and nothing else is added unless you include it, which is why this command is ideal for creating one-line logs, custom multi-line templates, or machine-readable output.

You can extend this by adding placeholders like %H (full hash), %ae (author email), %ad (author date), %d (ref names), and %b (body), using separators such as \n for newlines or \t for tabs; other useful flags that work well with this command include --graph to draw an ASCII commit tree, --oneline (a shorthand equivalent to --pretty=format:'%h %s' --abbrev-commit), --abbrev-commit to shorten hashes, --decorate to show branch/tags, and range/limiting options like -n 10, --since="2.weeks", or main..<feature-branch> to focus on specific commits without changing the formatting behavior.

Common variants include git log --pretty=oneline for a simple hash-and-subject view, git log --pretty=format:'%h - %an, %ar : %s' for a compact human-friendly summary, git log --graph --pretty=format:'%h %s' --abbrev-commit for a visual branch structure, and git log --pretty=format:'%H' when you only need full hashes for scripting; closely related commands are git show --pretty=format:<format_string> <commit> to inspect a single commit using the same formatting rules, and git rev-list --pretty=format:<format_string> <range> when you want similar custom formatting but with more script-oriented listing behavior.

Examples:

  • git log --pretty=format:'%h - %an: %s'
  • git log --pretty=format:'%H %ae %ad %s'
  • git log --graph --pretty=format:'%h %s (%an)' --abbrev-commit
Manual page
git log
Related commands

Welcome to GitExamples!

Sign in to gitexamples