gitgithubgit-loggit-format

"More content" indicator for commit messages in git log --online?


If you view commit history in Github, eg, it will indicate using ellipsis which commit message have additional lines of content beyond their subject line:

Github history

When using:

git log --oneline

in the terminal, is there any way to get a similar "more content" indicator?


Solution

  • --oneline is a standard (and very handy) shortcut format, but for anything more specific, you can rely on --pretty and build your output.

    Try this pretty format (doc)

    git log --pretty=format:"%h %d %s%<(1,trunc)% b%-"
    

    Coloring

    If you don't want to lose the automatic coloring of --oneline, you can replicate the most part with %C(<color>) (doc)

    git log --pretty=format:"%C(yellow)%h %C(auto)%d %C(reset)%s%C(red)%<(1,trunc)% b%-"
    

    Alias

    Of course with such formats, since nobody wants to type that each time, it's nearly mandatory to make it an alias

    git config --global alias.line 'git log --pretty=format:"%C(yellow)%h %C(red)%d %C(reset)%s%C(red)%<(1,trunc)% b%-"'
    
    # which combines well with most options
    git line
    git line -10
    git line --all --graph
    

    (finally, you can also put the -10 or any other value as a default in the shortcut, it'll be used unless you override it explicitly, very handy)