git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Colorize matches for git log --grep=pattern?

From
Jeff King <peff@peff.net>
Date
Nov 1, 2017, 18:50 UTC
Message-ID
<20171101185026.d4ljyywz3fepgoth@sigill.intra.peff.net>
In-Reply-To
<otc9a3$h9a$1@blaine.gmane.org>
On Wed, Nov 01, 2017 at 11:57:14AM +0100, Sebastian Schuberth wrote:
Show 5 quoted lines
> is there a way to colorize / highlight the pattern matched by
> 
>     git log -E -i --grep=pattern
> 
> in the console output?

I don't think so. The grep code _does_ know about colorizing matches (which is why "git grep --color" works), but for the output code path for commit messages doesn't use grep at all (it couldn't, because we're not just showing the relevant lines but selecting the whole commit).

So I think it would have to be reimplemented separately.

The best workaround I could come up with is passing the output through a highlighting script:

  git log --grep=foo --color |
  perl -pe 's/foo/\x1b[1;31m$&\x1b[m/' |
  less
Pretty hacky.
-Peff
Previous: Sebastian SchuberthNext: Sebastian Schuberth
Message 2 of 3 in “Colorize matches for git log --grep=pattern?”
  1. Sebastian SchuberthNov 1, 2017
  2. Jeff KingNov 1, 2017
  3. Sebastian SchuberthNov 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.