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

[BUG] `git diff` treats an unchanged line as modified

From
HLHao Lee <haolee.swjtu@gmail.com>
Date
Dec 24, 2019, 17:50 UTC
Message-ID
<CA+PpKPm0_zXr978Mw8h7owHBChx-uqVCdjrtuh45uOS-A_0qrA@mail.gmail.com>
Here are two files `old` and `new`.
The content of `old` file:
```
kasan_poison_slab(page);//
shuffle = shuffle_freelist(s, page);//

if (!shuffle) { for_each_object_idx(p, idx, s, start, page->objects) { setup_object(s, page, p); if (likely(idx < page->objects)) ```

The content of `new` file:
```
kasan_poison_slab(page);

shuffle = shuffle_freelist(s, page); ```

When using git to compare these two files, the result is:
```
diff --git a/old b/new
index 474ab07..d432a67 100644
--- a/old
+++ b/new
@@ -1,11 +1,6 @@



-       kasan_poison_slab(page);//
-
-       shuffle = shuffle_freelist(s, page);//
-
-       if (!shuffle) {
-               for_each_object_idx(p, idx, s, start, page->objects) {
-                       setup_object(s, page, p);
-                       if (likely(idx < page->objects))
+       kasan_poison_slab(page);
+
+       shuffle = shuffle_freelist(s, page);
```

However, the Linux diff command gives the following result:

```
--- old 2019-12-25 00:56:40.000000000 +0800
+++ new 2019-12-25 01:12:48.000000000 +0800
@@ -1,11 +1,6 @@



- kasan_poison_slab(page);//
+ kasan_poison_slab(page);

- shuffle = shuffle_freelist(s, page);//
-
- if (!shuffle) {
- for_each_object_idx(p, idx, s, start, page->objects) {
- setup_object(s, page, p);
- if (likely(idx < page->objects))
+ shuffle = shuffle_freelist(s, page);
```

I think the latter is correct because the fifth line is not changed
and it's still a line which only contains a whitespace.

Steps to Reproduce:

curl -L https://git.io/JeFNy | base64 -d > file.tgz
tar -xf file.tgz
git diff --no-index old new
Next: Junio C Hamano
Message 1 of 3 in “[BUG] `git diff` treats an unchanged line as modified”
  1. Hao LeeDec 24, 2019
  2. Junio C HamanoDec 24, 2019
  3. Hao LeeDec 25, 2019

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.