{"thread":{"id":"27927","subject":"[BUG] diff and blame difference","startedAt":"2011-07-26T14:10:05Z","lastAt":"2011-07-26T19:25:51Z","messageCount":2,"participants":["Semyon Kirnosenko","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"172062","messageId":"4E2ECABD.7050601@gmail.com","threadId":"27927","inReplyTo":null,"subject":"[BUG] diff and blame difference","fromName":"Semyon Kirnosenko","fromEmail":"semyon.kirnosenko@gmail.com","sentAt":"2011-07-26T14:10:05Z","receivedAt":"2011-07-26T14:10:05Z","isPatch":false,"sender":{"key":"semyon.kirnosenko@gmail.com","avatar":null},"body":"Hi.\n\nAgain, I have to post about diff and blame difference problem.\nThe initial discussion ends here:\nhttp://permalink.gmane.org/gmane.comp.version-control.git/165012\n\nI have the same problem and now it's about non-whitespace lines. The \nproblem is some line is marked in diff as added, but in blame it is \nmarked as added in some older revision. And vice versa line is not \nmarked as added in diff but it is marked in blame. Here are several \nexamples from git repo:\n\nDiff error in revision 198b0fb635ed8a007bac0c16eab112c5e2c7995c in file \ndate.c.\nLine 184: added in diff, but blame say otherwise.\nLine 215: added in diff, but blame say otherwise.\nLine 219: added in diff, but blame say otherwise.\nLine 259: added in diff, but blame say otherwise.\nLine 260: added in diff, but blame say otherwise.\nLine 193: not added in diff, but blame say otherwise.\nLine 212: not added in diff, but blame say otherwise.\nLine 222: not added in diff, but blame say otherwise.\nLine 300: not added in diff, but blame say otherwise.\nLine 315: not added in diff, but blame say otherwise.\n\nTo get diff and blame i've used the following commands:\ngit --git-dir=D:\\src\\git\\.git diff-tree -p \n198b0fb635ed8a007bac0c16eab112c5e2c7995c -- date.c > diff-tree\ngit --git-dir=D:\\src\\git\\.git blame -l -s \n198b0fb635ed8a007bac0c16eab112c5e2c7995c -- date.c > blame\n\n\nI have sent this before, but did not receive any response. I just need \nsome type of answer. Something like \"we will fix it\" or \"we don't care \nabout it\".\n"},{"id":"172092","messageId":"7vzkk0q1xc.fsf@alter.siamese.dyndns.org","threadId":"27927","inReplyTo":"4E2ECABD.7050601@gmail.com","subject":"Re: [BUG] diff and blame difference","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-26T19:25:51Z","receivedAt":"2011-07-26T19:25:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"You need to realize that diff is to express changes as deletion and\ninsertion for humans, while blame is not about expressing changes, but\nshowing the origin of each line.\n\nAn example. Imagine you have a file with ten lines (whose contents you\nwill call A, B, C, ..., J). Starting from this initial state, if you make\nthe first three lines to \"X B Y\", think about what happens.\n\nMost likely, \"diff\" would give you a single hunk that says \"you deleted A\nB C and then inserted X B Y\", making the result look as if B was added by\nyour change.\n\nBut that is not the only possible output \"diff\" could produce.  It would\nalso be a valid output if it instead showed two hunks. One hunk would\ndelete A from the first line and add X in its place, and the other hunk\nwould delete C from the third line and add Y in its place.  But \"git diff\"\nwould not do that, in order to make it more readable for humans, these\nadjacent changes that _could_ be in separate hunks are coalesced into a\nsingle hunk.\n\nBut \"blame\" is not constrained by the requirement to show a readable\n\"patch\" to humans. It is allowed to, and it does, see this change through,\nnotice and show that B stayed from the older version. Only lines X and Y\nare new.\n\nInstead of \"git --git-dir=D:\\src\\git\\.git diff-tree -p\", run it with zero\nlines of context and you will see lines 184 and 215 indeed stayed from the\nprevious version, which exactly explains why you thought 184 was added by\nlooking at the output of \"diff\". You can tell that in fact the previous\nversion already had that contents there by looking at \"show -U0\" output.\n\nAnd that is what \"blame\" told you.\n\nAnother example that you may not have noticed with just \"blame\", but would\nhave noticed if you gave it -M or -C option is this.\n\nStarting from the same ten lines, If you move the first three lines and\ntuck them at the end after J, diff needs to say \"remove the first three\nlines\" and then \"add these three lines at the end\". There is no way for\ndiff to say \"these three lines were moved\". If you look at \"diff\" output,\nyou would think \"the last three lines A B C were added\", while \"blame\" can\nsee it through and can say \"A B C stayed from the beginning\".\n"}]}