Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make 'git log' decorate by default

Tags:

git

git-log

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.

like image 347
Benubird Avatar asked Feb 06 '14 15:02

Benubird


People also ask

What is git log in decorating?

The --decorate flag makes git log display all of the references (e.g., branches, tags, etc) that point to each commit. This lets you know that the top commit is also checked out (denoted by HEAD ) and that it is also the tip of the main branch.

What is git log -- all?

To show all of the branches, add --all to your git log command. So basically, without --all you only see the commits that actually make up your current branch.

What is git log used for merge local master?

The git log command shows a list of all the commits made to a repository. You can see the hash of each Git commit, the message associated with each commit, and more metadata. This command is useful for displaying the history of a repository.


2 Answers

git config log.decorate auto

For a global setting, add the --global parameter.

So it would be:

git config --global log.decorate auto 

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

like image 193
Jakub Avatar answered Sep 25 '22 09:09

Jakub


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".

That means you would need to override that option on command line, to get back to the old behavior (for just one log execution):

git -c log.decorate=false log 

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, especially 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.

like image 31
VonC Avatar answered Sep 21 '22 09:09

VonC