With recent versions of git (1.7… 2.21 here) you can change your default format to a named format or the format string. And while you're doing it you may as well add some PRETTY FORMATS auto colors. Also I find it easier to edit the file rather than use the commands; but I start with them to get the right config file format first, and then tinker.
The default is changed with:
git config --global --add format.pretty \
"%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s"
Resulting in the addition to your .gitconfig
of:
[format]
pretty = %C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s
It is, however, probably more useful to you to add a named format as mentioned in the later part of your question.
A named format is added with:
git config --global pretty.dateline \
"format:%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s"
Or by adding to your .gitconfig
as:
[pretty]
dateline = format:%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s
Used in combination:
If you add both, you could make them read:
[pretty]
dateline = format:%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s
[format]
pretty = dateline
Caveats:
The difference in the format:
prefix should be noted, and personally I like to leave the default pretty format as medium
. As you know the %ad
part can be modified by --date=relative
or any of default
, iso8601
, local
, raw
, relative
, rfc2822
, short
; so I like to use it like:
git log -25 --pretty=dateline --date=short -- when/was/this/changed.txt