5

Based on my understanding, the command git blame is supposed to show, for each line in a file, the author and the commit in which the line was last modified. So for example, if I run git blame -- "<filename>" and get the following output for line 5:

106b77db (Walrus 2016-03-24 10:01:36 +0800   5) .root {

it means the line .root { originated from the author Walrus in the commit 106b77db. In other words, if I inspect the patch produced by 106b77db using git show -p 106b77db, I would expect the line +.root { to show up in the diff. Indeed, this is the case.

Snippet from 106b77db's diff for <filename>:

 /* JavaFX CSS - Leave this comment until you have at least create one rule       which uses -fx-Property */
+.root {
+   -fx-background-color: transparent;
+}
+

Now, when I run git blame -w -- "<filename>", (the -w option ignores whitespace changes, i.e. traces each line backwards in time to find the last author which introduced non-whitespace changes to that line), I now get the following output for line 5:

b6a6e8a2 (Walrus 2016-03-31 23:32:50 +0800   5) .root {

However, when I inspect the patch for b6a6e8a2 using git show -p b6a6e8a2, the diff shows .root { rather than +.root { as expected.

Snippet from b6a6e8a2's diff for <filename>:

+
+/* setting window to be transparent================================ */
 .root {
    -fx-background-color: transparent;
-}
-

Has Git given me erroneous output, because according to the diff, the line .root { was not modified at all in the commit b6a6e8a2?

I am using Git 2.13.3.windows.1.

EDIT: the repository is https://github.com/cs2103jan2016-f14-2j/main, and the file is JimplePlanner/src/application.css. After upgrading to Git 2.16.1.windows.4, the issue still persists.

Tao
  • 13,457
  • 7
  • 65
  • 76
  • 1
    I can't reproduce this behavior in simple tests, so you'll probably need to give more specific information. Instead of *describing* the commands you issued and the results, you should show the exact command as it was typed and the exact output as it was printed. – Mark Adelsberger Feb 15 '18 at 13:35
  • 2
    ...or better yet, either link to the repository in question or set up a reproducible example to which we can have access. – larsks Feb 15 '18 at 13:44
  • 1
    @larsks Added the full commands, relevant output snippets, the repository link and filename. I did not show the full output as it is hundreds of lines long, and most of it is not relevant to the question. – user9284152 Feb 15 '18 at 13:56
  • @MarkAdelsberger Updated. Could not tag you and larsks in the same comment. – user9284152 Feb 15 '18 at 14:08
  • Can anyone at least verify that this example is reproducible on their machine? – user9284152 Feb 15 '18 at 22:09
  • Bump, hope someone is willing and able to help. – user9284152 Feb 28 '18 at 15:01

1 Answers1

1

five years later I encountered the same issue and floundered in trying to understand what happened.

It turned out that when you ignore whitespace, git sometimes understands the change to have been a completely different one, because of a repeating pattern that, after whitespace elision, changes the location of the detected "smallest change".

Running git diff -w vs git diff on the "incorrect" revision (in your case, b6a6e8a) illustrates the problem:

git diff b6a6e8a~..b6a6e8a:

diff --git a/JimplePlanner/src/application.css b/JimplePlanner/src/application.css
index e4634ef..c0cc44b 100644
--- a/JimplePlanner/src/application.css
+++ b/JimplePlanner/src/application.css
@@ -1,248 +1,108 @@
 /* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
+
+/* setting window to be transparent================================ */
 .root {
        -fx-background-color: transparent;
-}
-
-.today-pane {

git diff -w b6a6e8a~..b6a6e8a:

diff --git a/JimplePlanner/src/application.css b/JimplePlanner/src/application.css
index e4634ef..c0cc44b 100644
--- a/JimplePlanner/src/application.css
+++ b/JimplePlanner/src/application.css
@@ -1,248 +1,108 @@
 /* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
-.root {
-       -fx-background-color: transparent;
-}
-
-.today-pane {
-       -fx-background-radius: 10px;
-    -fx-background-color: white;
-    -fx-border-color: grey;
-    -fx-border-radius: 10px;
-}
-
-.list-view {
-    -fx-padding: 3px ;
-    -fx-background-color: transparent;
-}
-
- .list-cell {
-    -fx-padding: 10px ;
-    -fx-background-color: transparent, -fx-background ;
-}

-
-.list-cell:empty {
-    -fx-padding: 10px;
+/* setting window to be transparent================================ */
+.root {
        -fx-background-color: transparent;
-    -fx-background-insets: 0 ;
-}
+}/*============================================++================== */

When whitespace is ignored, the diff algorithm ends up counting .root { as removed in one place, and added back in a different place.

This is just a consequence of ignoring whitespace - it will sometimes interpret changes that were made substantially differently to how you think about them; more often than when not ignoring whitespace.

Tao
  • 13,457
  • 7
  • 65
  • 76