Search code examples
windowsgitgit-log

Colors and authors in git log on Windows?


Using Windows 10 Pro 64-bit I found a nice command to list the Git history, showing HEAD, branches, and tags as stand-out colors. Nice!

git log --oneline --decorate --graph --all

But I don't see any dates or authors! So I find another nice command:

git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

Also very nice---now I can see dates and authors. But all the pretty colors are gone (except for the graph). HEAD, branches, and tags are all the same color as the rest of the log, making it hard to pick them out.

How do I get the colors back for the commit pointers while keeping the date and authors?


Solution

  • You can wrap your format string with %C(auto) and %C(reset) to color the output automatically, like so:

    %C(auto)<insert your formatting here>%C(reset)
    

    So, using the format you provided:

    git log --pretty=format:"%C(auto)%h %ad | %s%d [%an]%C(reset)" --graph --date=short
    

    It will use git's default color for things like branches (remote in red, local in green, HEAD in cyan etc) and commit refs.