Git how to save a preset git log --format Git how to save a preset git log --format git git

Git how to save a preset git log --format


In newer versions of Git (confirmed with v1.7.8) it is possible to set named pretty-print log formats using git config pretty.named_format. These can be set at a machine-wide, user or file level with the <file-option> argument.

To create a log format called jespers_favourite or the whole machine use --system

git config --system pretty.jespers_favourite "%h%x09%an%x09%ad%x09%s"

For single user use '--global'

git config --global pretty.jespers_favourite "%h%x09%an%x09%ad%x09%s"

Leaving the <file-option> argument blank will default to setting the config file of the current repository, .git/config unless defined otherwise.


Considering the git log manual page mentions:

--pretty[=<format>]--format[=<format>]

Pretty-print the contents of the commit logs in a given format, where can be one of oneline, short, medium, full, fuller, email, raw and format:. When omitted, the format defaults to medium.

the <format> can only have predefined values.
That only leaves you the possibility to define an alias as a shortcut for that command.

[alias]        jespers_favourite = log --pretty=format:"%h%x09%an%x09%ad%x09%s"

or

[alias]        compactlog = log --pretty=format:"%h%x09%an%x09%ad%x09%s"


You can configure the default pretty format using git-config. From the git-config documentation:

 format.pretty           The default pretty format for log/show/whatchanged command, See git-log(1), git-show(1), git-whatchanged(1).

For example:

git config --add format.pretty fuller

or original poster's desired format:

git config --add format.pretty "%h%x09%an%x09%ad%x09%s"

Like with other git config settings, format.pretty may be set at the global, system, or repository scope (default).