How to make git log decorate by default

2019-03-12 06:35发布

问题:

I frequently type git log when what I actually want is git log --decorate. How do I make it decorate by default?

I have seen lots of answers of the form "make an alias lg and then type git lg instead of git log". But, I can't find anywhere how to change the default behaviour of git log itself. alias log does not work.

回答1:

git config log.decorate auto

for global setting add --global param.

so it would be git config --global log.decorate auto

The aliases are made with git config alias.lg "log --decorate"

Edit: Updated log.decorate true to auto based on answer from VonC as this is now the recommended way of doing so.



回答2:

Update April 2017, 3 years later:

With Git 2.13 (Q2 2017), no need for configuration: --decorate is the default!

See commit 940a911 (24 Mar 2017) by Alex Henrie (alexhenrie).
(Merged by Junio C Hamano -- gitster -- in commit d9758cf, 11 Apr 2017)

The default behaviour of "git log" in an interactive session has been changed to enable "--decorate".


Original answer (mid 2014)

Note: since git 2.1.0-rc0 (July 2014), Linus Torvalds himself introduced a decorate=auto option.
That is more precise than just decorate=true, espcially for scripting purpose, as explained below.

See commit 1571586 by Linus Torvalds (torvalds):

This works kind of like "--color=auto" - add decorations for interactive use, but do not change defaults when scripting or when piping the output to anything but a terminal.

You can use either

[log]
     decorate=auto

in the git config files, or the "--decorate=auto" command line option to choose this behavior.



标签: git git-log