Search code examples
gitgit-log

How to override a git log pretty format?


The available built-in pretty formats don't exactly fit my need (or my taste):

https://git-scm.com/docs/pretty-formats

git log --decorate --graph --all --pretty=short is almost what I want, but I'd like the commit date to be shown as well...

git log --decorate --graph --all --pretty=medium is nice, but I don't want to the full commit message. I'd like only the first line of the commit message to be shown...


So I tried to define my own pretty format, just like 'medium' but without the full commit message, like so:

git log --decorate --graph --all --pretty=format:'commit %H%nAuthor: %an%nDate: %ad%n%n%s%n'

One problem is the branch names are not shown anymore. Another problem is the logs are not in color anymore. How can I do that correctly?

Ideally, I'd just like to override --pretty=medium so that it will not show the full commit message, but only the title of the commit (or to override --pretty=short for it to show the date). Is this only possible (to override a built-in pretty format)? If yes, how?


Solution

  • --decorate does not work with an own format. If you want it, you need to use %d or %D. And if you like you can also add some coloring to get similar output like for medium you probably want something like:

    git log --graph --all --pretty=format:'%C(auto,yellow)commit %H%C(auto,green bold)%d%Creset%nAuthor: %an%nDate: %ad%n%n%s%n'