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

diff --color-words breaks spacing

From
Phil Hord <phil.hord@gmail.com>
Date
Jan 24, 2017, 17:39 UTC
Message-ID
<CABURp0ryBtLALEnzRdoeYeUUdrzBxiT3+yTvW6B=vpqMG3p1Rw@mail.gmail.com>

I noticed some weird spacing when comparing files with git diff --color-words. The space before a colored word disappears sometimes.

$ git --version git version 2.11.0.485.g4e59582ff

echo "FOO foo; foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b FOOfoo; foo = barbaz

There should be a space after FOO in the diff, even if git doesn't think "foo" and "foo;" are the same word.

If I remove the semicolon, it looks better, but in fact it only moves the error later. The missing space is now between the two "foo" words.

echo "FOO foo foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b FOO foofoo = barbaz

Here's the same with the color codes changed to text for purposes of this email:

echo "FOO foo; foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b | tr \\033 E FOOE[31mfoo;E[m foo = E[31mbarE[mE[32mbazE[m

echo "FOO foo foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b | tr \\033 E FOO fooE[31mfooE[m = E[31mbarE[mE[32mbazE[m

Next: Jeff King
Message 1 of 2 in “diff --color-words breaks spacing”
  1. Phil HordJan 24, 2017
  2. Jeff KingJan 25, 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.