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

git diff --word-diff problem

From
ISIvan Shirokoff <shirokoff@yandex-team.ru>
Date
Jan 12, 2012, 09:05 UTC
Message-ID
<4F0EA23D.3010603@yandex-team.ru>

Hello. I've got a couple of generated files with obfuscated code. I want to word-diff them just to make sure that everything is right.

The thing is when word-diff gets oneline file without newline at the end it compares it with regular line by line diff.

Here is an example. Two one line files generated with perl -e "print 'a 'x10" > file

git diff --word-diff=plain file1 file2
diff --git a/file1 b/file2
index 3526254..0515a63 100644
--- a/file1
+++ b/file2
@@ -1 +1 @@
[- a a a a a a a a a a-]
  No newline at end of file
  {+a a a a a ab a a a a+}

Git shows that the whole line is different.
And if I add newlines to that files everything works just as expected

git diff --word-diff=plain file1 file2
diff --git a/file1 b/file2
index 1756d83..1ec45b9 100644
--- a/file1
+++ b/file2
@@ -1,2 +1,2 @@
  a a a a a [-a -]{+ab +}a a a a

Is that a bug or I've missed explanation in docs?
-- 
Ivan Shirokoff
Next: Thomas Rast
Message 1 of 3 in “git diff --word-diff problem”
  1. Ivan ShirokoffJan 12, 2012
  2. word-diff: ignore '\ No newline at eof' markerThomas Rast, Jan 12, 2012
  3. Junio C HamanoJan 12, 2012

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.