{"thread":{"id":"54862","subject":"git diff --ignore-space-change -- ignore whitespace prefers unmodified next line to modified one in patch","startedAt":"2020-12-21T15:02:43Z","lastAt":"2020-12-21T15:02:43Z","messageCount":1,"participants":["Dipl. Ing. Sergey Brester"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"412715","messageId":"8a6a45cbda00ae1f0f679daf62fba27c@sebres.de","threadId":"54862","inReplyTo":null,"subject":"git diff --ignore-space-change -- ignore whitespace prefers unmodified next line to modified one in patch","fromName":"Dipl. Ing. Sergey Brester","fromEmail":"serg.brester@sebres.de","sentAt":"2020-12-21T14:43:59Z","receivedAt":"2020-12-21T15:02:43Z","isPatch":false,"sender":{"key":"serg.brester@sebres.de","avatar":null},"body":"Steps to reproduce the issue:\n\n  1. create two simple C files and diff both ignoring whitespaces:\n```\nprintf \"if (some_var1) {\\n  do {\\n    some-code\\n  } while (1);\\n}\\n\" > \na.c\nprintf \"if (some_var1) {\\n  do {\\n    if (some_var2) {\\n      \nsome-code\\n    }\\n  } while (1);\\n}\\n\" > b.c\ngit diff --ignore-space-change --no-index a.c b.c\n```\n     which would produce fully correct resulting patch:\n```\ndiff --git a/a.c b/b.c\n--- a/a.c\n+++ b/b.c\n@@ -1,5 +1,7 @@\n  if (some_var1) {\n    do {\n+    if (some_var2) {\n        some-code\n+    }\n    } while (1);\n  }\n```\n     but this behavior will change if line 5 would be equal line 6 \n(containing only brace ...).\n\n  2. now we'll modify that a bit (e. g. use while instead of do, to make \nthe lines more similar\n     (containing only braces):\n```\nprintf \"if (some_var1) {\\n  while (1) {\\n    some-code\\n  }\\n}\\n\" > a.c\nprintf \"if (some_var1) {\\n  while (1) {\\n    if (some_var2) {\\n      \nsome-code\\n    }\\n  }\\n}\\n\" > b.c\ngit diff --ignore-space-change --no-index a.c b.c\n```\n     which then would produce this result:\n```\ndiff --git a/a.c b/b.c\n--- a/a.c\n+++ b/b.c\n@@ -1,5 +1,7 @@\n  if (some_var1) {\n    while (1) {\n+    if (some_var2) {\n        some-code\n      }\n+  }\n  }\n```\n     As one can see, a line 6 instead of line 5 is marked as new (thereby \nline 6 was **completely unmodified**).\n     In my opinion correct would be this variant (also similar patch of \ntest in step 1):\n```\ndiff --git a/a.c b/b.c\n--- a/a.c\n+++ b/b.c\n@@ -1,5 +1,7 @@\n  if (some_var1) {\n    while (1) {\n+    if (some_var2) {\n        some-code\n+    }\n    }\n  }\n```\n\nI understand that using --ignore-space-change both lines are quasi \n\"equal\", and then first \"change\"\nwill be noticed as a new created line, but from point of view of the \ndeveloper (and common sense)\nit is very strange either, especially if one considers that whole code \nstarting from line 6 is totally unmodified.\n\nThis causes that on some much complex nested blocks, this simple \"first \nwins\" logic (without a simple look-ahead),\nconfuses still more (because affects several unmodified blocks, braces \netc), especially if some\nconflicts should be resolved or a 3-way merge/review takes place.\n\nThis makes the usage of option \"--ignore-space-change\" pretty pointless, \nbecause the diff of larger nested blocks\nis often error prune on braces, brackets etc, so the review is often \nneedless complicated.\n\n\n[System Info]\ngit version:\ngit version 2.28.0.windows.1\ncpu: x86_64\nbuilt from commit: 77982caf269b7ee713a76da2bcf260c34d3bf7a7\nsizeof-long: 4\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Windows 10.0 18363\ncompiler info: gnuc: 10.2\nlibc info: no libc information available\n$SHELL (typically, interactive shell): <unset>\n\n-- \n\nRegards,\nSergey Brester\n\n"}]}