When you run git log --decorate --pretty=oneline
the output will have entries like (HEAD, refs/published/master, master)
with coloration.
I also have the following in my gitconfig:
[color "branch"]
current = yellow reverse
local = yellow
remote = green
How do you replicate those colors when doing a custom format like the following?
git log --decorate --stat --graph --pretty=format:"%d %Cgreen%h%Creset (%ar - %Cred%an%Creset), %s%n"
The config option
log.decorate
can enable/disable default decorations in logs.Once that is done you can use
color.decorate.*
to play with the colorsParenthesize them:
So
%C(yellow reverse)
would work.Some may want to use this :
%C(colorname)
This doesn't need to change the color config.Example : Coloring the author name in yellow
Regular ANSI colors should work https://en.wikipedia.org/wiki/ANSI_escape_code
As of git 1.8.3 (May 24, 2013), you can use
%C(auto)
to decorate%d
in the format string ofgit log
.From the release notes:
The
git log --decorate
will put by default:and can be changed through
color.decorate
config.But the
git log --format
don't offer a way to display specifically theHEAD
or remotes or branch: all three are displayed through%d
, with one color possible.Update May 2013, as mentioned below by Elad Shahar (upvoted), git 1.8.3 offers one more option:
This Atlassian blog post comments that this feature is part of several others focused on format (
git rebase
,git count-objects
) and colors (git branch -vv
)This comes in addition of the previous
auto,reset
of 1.8.2, which automatically disables colors when the output is not used for a terminal1Note: git 2.4+ (Q2 2015) will do a better job of resetting color around branch names.
See commit 5ee8758 by Junio C Hamano (
gitster
):Note that git 2.5 (Q2 2015) fixes a bug:
See commit 429ad20 by Junio C Hamano (
gitster
), 13 May 2015.(Merged by Junio C Hamano --
gitster
-- in commit fd70780, 22 May 2015)Git 2.9.x+ (Q3 2016) will fix another bug and honor
color=auto
for%C(auto)
Git 2.10.2 (Oct. 2016) fixes other bugs with commit 82b83da (29 Sep 2016), and commit c99ad27 (17 Sep 2016) by René Scharfe (``).
(Merged by Junio C Hamano --
gitster
-- in commit 76796d4, 28 Oct 2016)