{"thread":{"id":"44799","subject":"Counter-intuitive result from diff -C --stat","startedAt":"2016-12-31T21:42:59Z","lastAt":"2017-01-01T01:15:49Z","messageCount":2,"participants":["Mike Hommey","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"308556","messageId":"20161228080916.72id4hzqxfbygtth@glandium.org","threadId":"44799","inReplyTo":null,"subject":"Counter-intuitive result from diff -C --stat","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2016-12-28T08:09:16Z","receivedAt":"2016-12-31T21:42:59Z","isPatch":false,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"Hi,\n\nSo I was checking out differences between two branches, accounting for\nfile moves with -C, and was surprised by the number of insertions and\ndeletions that it indicated, because it was telling me I had removed\nmore than I added, which I really don't think is true.\n\nI took a closer look, and what happens is that I had a lot of stuff in\na __init__.py file that I moved to another file, while keeping a now\nnew, empty, __init__.py file.\n\nWhich means while diff counts the deletions from __init__.py, it doesn't\ncount the additions from the move because it is a move, leading to a\ncounter-intuitive result.\n\nHere's how to reproduce in case code makes more sense than prose:\n\n/tmp$ git init g\nInitialized empty Git repository in /tmp/g/.git/\n/tmp$ cd g\n/tmp/g$ echo foo > foo\n/tmp/g$ git add foo\n/tmp/g$ git commit -m foo\n[master (root-commit) 14749a7] foo\n 1 file changed, 1 insertion(+)\n create mode 100644 foo\n/tmp/g$ git mv foo bar\n/tmp/g$ touch foo\n/tmp/g$ git add foo\n/tmp/g$ git commit -m bar\n[master 9fbf50e] bar\n 2 files changed, 1 insertion(+), 1 deletion(-)\n create mode 100644 bar\n/tmp/g$ git diff HEAD~ -C --stat\n foo => bar | 0\n foo        | 1 -\n 2 files changed, 1 deletion(-)\n\nI'm actually not sure what the right thing would be. I guess this is a\ncase where -B should help, but it doesn't.\n\nAny thoughts?\n\nMike\n"},{"id":"308559","messageId":"xmqqd1g760n4.fsf@gitster.mtv.corp.google.com","threadId":"44799","inReplyTo":"20161228080916.72id4hzqxfbygtth@glandium.org","subject":"Re: Counter-intuitive result from diff -C --stat","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-01-01T01:15:43Z","receivedAt":"2017-01-01T01:15:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Hommey <mh@glandium.org> writes:\n\n> Hi,\n>\n> So I was checking out differences between two branches, accounting for\n> file moves with -C, and was surprised by the number of insertions and\n> deletions that it indicated, because it was telling me I had removed\n> more than I added, which I really don't think is true.\n>\n> I took a closer look, and what happens is that I had a lot of stuff in\n> a __init__.py file that I moved to another file, while keeping a now\n> new, empty, __init__.py file.\n>\n> Which means while diff counts the deletions from __init__.py, it doesn't\n> count the additions from the move because it is a move, leading to a\n> counter-intuitive result.\n\nIntuition is in the eyes of observer.  \n\nA pairing of the original and the result you saw might be not very\nuseful (which I have no opinion on), but in the context of the\nchosen pairing of the original and the result, in order to produce\nthe final result, you started from a copy of the original and\nremoved quite a lot while adding just a bit, so what you saw was an\noutcome that was deliberately designed.\n\n"}]}