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

Re: Potential bug in --color-words output

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 10, 2022, 13:51 UTC
Message-ID
<39so8720-p05o-9qns-1o8o-q783271n40os@tzk.qr>
In-Reply-To
<e2164b04-98de-6f19-6c33-6979c1a328ff@gmail.com>
Hi Simeon,
On Fri, 28 Oct 2022, Simeon Krastnikov wrote:
Show 6 quoted lines
> Given an initial file with the contents "not to be", which I then change to
> "to be", the output of 'git diff --color-words', is
>
>   notto be
>
> with the first three letters colored red.
This seems to be a limitation of the original `--color-words` design.

FWIW I find myself using these three aliases all the time now, i.e. using a different word-coloring mode that works much better for me:

	[alias]
		cwdiff = diff --color-words=\"[A-Za-z0-9_]+|.\"
	        cwlog = log --color-words=\"[A-Za-z0-9_]+|.\"
		cwshow = show --color-words=\"[A-Za-z0-9_]+|.\"
Explanation: the regex `[A-Za-z0-9_]+|.` treats runs of alphanumerical
characters (including the underscore) as words, and also treats any
individual characters that do not fall into that category as "words".

The only downside of this is that the coloring does not help identifying white-space differences because only the foreground color is changed (which does not result in any visible difference for white-space characters).

Maybe these aliases help you, too?

Ciao, Johannes

Previous: Johannes SixtNext: Stefan Beller
Message 3 of 4 in “Potential bug in --color-words output”
  1. Simeon KrastnikovOct 28, 2022
  2. Johannes SixtNov 8, 2022
  3. Johannes SchindelinNov 10, 2022
  4. Stefan BellerNov 7, 2022

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.