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

UTF-8-safe way for char-level-diff

From
Danny Lin <danny0838@gmail.com>
Date
Jan 19, 2018, 14:13 UTC
Message-ID
<CAMbsUu7P6RGpyDm+tKbBhgPyxoTYP3Zs5rjt302O8SH-H8ujeQ@mail.gmail.com>

Git has a diff.wordRegex config that allows the user to specify a regex that defines a word. Setting diff.wordRegex to "." works well for a char-level diff for ASCII chars, but not for UTF-8 chars.

For example, if a file (encoded by UTF-8) with text "一人" is changed to "丁人", "git diff --word-diff=color" gets "<E4><B8><80><81>人" (where "<80>" is red and "<81>" is green) instead of desired "一丁人" (where "一" is red and "丁" is green). This could be very annoying when diff-ing files containing CJK chars.

Git diff.wordRegex seems to implement a very basic regex that doesn't support matching char range by encoding such as "\x41" for "a". Is there a way to make the char-level diff work correctly? If not, maybe we should implement a way to allow it.

Message 1 of 1 in “UTF-8-safe way for char-level-diff”
  1. Danny LinJan 19, 2018

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.