Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling git log parameters by default

I like the way that the following command prints out git logs:

git log --oneline --decorate --graph

I would like to make that the default format whenever I use git log. Is there a way to edit ~/.gitconfig to enable oneline, decorate, and graph by default?

And yes, I'm aware that I can alias those options to another git command alias, but I'd rather that log just print out using those options by default.

like image 678
emmby Avatar asked Sep 06 '14 15:09

emmby


1 Answers

Git allows you to activate --oneline and --decorate by default for log, show, etc.:

git config --global format.pretty oneline
git config --global log.decorate short

However, as of v2.1.0 v2.2.2, Git does not allow you to activate --graph by default. One way around that (adapted from this SuperUser answer) is to define the following function in your .<shell>rc file:

git() {
    if [ "$1" = "log" ]
    then
        command git log --graph "${@:2}";
    else
        command git "$@";
    fi;
}

One caveat (pointed out by hvd in his comment): if you specify options between git and log, as in

git -c log.showroot=false log -p

then, because the first argument is -c and not log, the --oneline --decorate --graph flags won't be used.

like image 159
jub0bs Avatar answered Oct 05 '22 20:10

jub0bs