I\'m using git for-each-ref
as a git alias to display a branch name and the subject of the last commit on that branch. That said, it\'s hard to tell where the branc
I don't see anything in the for-each-ref
man page that suggests it supports backslash-escape sequences like \033
. If you replace \033
(and \e
) with a literal escape character, it seems to work just fine.
Cupcake says that for-each-ref
also supports %xx
hex escape sequences, which would look like:
[alias]
logbranch = "for-each-ref --sort=-committerdate refs/heads/ --format='[%1B[0;31m]%(refname:short)[%1B[m] %(subject)' "
This also works fine on my system.
Git 1.9/2.0 (Q1 2014) will introduce color formatting for git for-each-ref
.
See commit fddb74c from Ramkumar Ramachandra (artagnon):
for-each-ref
: introduce %(color:...)
for colorEnhance '
git for-each-ref
' with color formatting options.
You can now use the following format in for-each-ref:
%(color:green)%(refname:short)%(color:reset)
where color names are described in
color.branch.*
.
With Git 2.15 (Q4 2017), you will be able to turn those colors on or off.
See commit 0c88bf5 (03 Oct 2017) by Jeff King (peff).
(Merged 04 Oct 2017)
provide
--color
option for all ref-filter usersWhen ref-filter learned about want_color() in 11b087a (
ref-filter
: consult want_color() before emitting colors, 2017-07-13), it became useful to be able to turn colors off and on for specific commands. Forgit-branch
, you can do so with--color
/--no-color
.But for
git-for-each-ref
andgit-tag
, the other users of ref-filter, you have no option except to tweak the "color.ui
" config setting. Let's give both of these commands the usual color command-line options.This is a bit more obvious as a method for overriding the config. And it also prepares us for the behavior of "
always
" changing (so that we are still left with a way of forcing color when our output goes to a non-terminal).