Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 466
Jonah Avatar asked Sep 12 '25 01:09

Jonah


1 Answers

--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%-"
  • %h shows the short-form hash;
  • %d shows the decorations (branches, tags, and HEAD);
  • %s shows the subject;
  • %<(1,trunc) truncates the body (% b) to .. if there's one;
  • %- removes unwanted empty lines that are appended as the result of truncating the body.

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)

like image 85
Romain Valeri Avatar answered Sep 13 '25 15:09

Romain Valeri