{"thread":{"id":"26216","subject":"log -p hides changes in merge commit","startedAt":"2011-01-06T17:07:10Z","lastAt":"2011-01-07T20:27:56Z","messageCount":6,"participants":["Phillip Susi","Junio C Hamano","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"159038","messageId":"4D25F6BE.7010300@cfl.rr.com","threadId":"26216","inReplyTo":null,"subject":"log -p hides changes in merge commit","fromName":"Phillip Susi","fromEmail":"psusi@cfl.rr.com","sentAt":"2011-01-06T17:07:10Z","receivedAt":"2011-01-06T17:07:10Z","isPatch":false,"sender":{"key":"psusi@cfl.rr.com","avatar":null},"body":"git log -p never shows a diff for merge commits.  It is nice that it\ndoes not show a giant diff that is the sum of all of the changes being\nmerged, but any manual changes made on top of the merge are also lost\nfrom view, and this is not good.  Here is a reproduction recipe:\n\ngit init\necho foo > a\ngit add a\ngit commit -m \"added a\"\ngit branch other\ngit checkout other\necho bar > b\ngit add b\ngit commit -m \"added b\"\ngit checkout master\ngit merge other\ngit log -p\n\nAt this point there is no diff shown in the log output.  This is fine\nsince there were no changes needed to complete the merge, and the\naddition of b is already documented in the merged commit.  The problem\nis that if you add --no-merge to the git merge, and then:\n\necho bart > a\ngit add a\ngit commit\n\nNow in addition to merging b, you have modified a, but git log -p still\nshows no diff, effectively hiding the fact that you snuck in a\nmodification to a during the merge.\n\nIt seems that adding -c or --cc to the log correctly shows the change to\na, but why is this not shown by default?\n"},{"id":"159056","messageId":"7vwrmhakdz.fsf@alter.siamese.dyndns.org","threadId":"26216","inReplyTo":"4D25F6BE.7010300@cfl.rr.com","subject":"Re: log -p hides changes in merge commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-01-06T19:43:04Z","receivedAt":"2011-01-06T19:43:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Susi <psusi@cfl.rr.com> writes:\n\n> It seems that adding -c or --cc to the log correctly shows the change to\n> a, but why is this not shown by default?\n\nDepends on the definition of \"correctly\", but perhaps you have a\ndefinition different from ours ;-) The \"patches\" shown with -c/--cc are\ndesigned to be different from normal diff so that people do not\naccidentally try to apply them with \"patch\" or \"git apply\".\n\n\"log -p\" omits merge commits by default because diffs of merges are mostly\nnot useful for ordinary purposes.  If you are trying to use \"log -p\" to\nreproduce a (part of) history, perhaps you would want to also study -m\noption.\n"},{"id":"159066","messageId":"4D262B05.2060306@cfl.rr.com","threadId":"26216","inReplyTo":"7vwrmhakdz.fsf@alter.siamese.dyndns.org","subject":"Re: log -p hides changes in merge commit","fromName":"Phillip Susi","fromEmail":"psusi@cfl.rr.com","sentAt":"2011-01-06T20:50:13Z","receivedAt":"2011-01-06T20:50:13Z","isPatch":false,"sender":{"key":"psusi@cfl.rr.com","avatar":null},"body":"On 1/6/2011 2:43 PM, Junio C Hamano wrote:\n> Depends on the definition of \"correctly\", but perhaps you have a\n> definition different from ours ;-) The \"patches\" shown with -c/--cc are\n> designed to be different from normal diff so that people do not\n> accidentally try to apply them with \"patch\" or \"git apply\".\n> \n> \"log -p\" omits merge commits by default because diffs of merges are mostly\n> not useful for ordinary purposes.  If you are trying to use \"log -p\" to\n> reproduce a (part of) history, perhaps you would want to also study -m\n> option.\n\nWhat I would like to do is be able to review a merge to sign off on it.\n While the full diff against the left parent would be a large and\nunhelpful amalgamation of the changes in the merged branch, any\nadditional changes made during the commit should not be hidden.  This\nallows someone performing the merge to effectively sneak in unintended\nchanges.  I would expect any such changes to be shown by log -p, but\nthis only seems to happen if you add -c.\n"},{"id":"159069","messageId":"20110106210438.GB15090@burratino","threadId":"26216","inReplyTo":"4D262B05.2060306@cfl.rr.com","subject":"Re: log -p hides changes in merge commit","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-01-06T21:04:38Z","receivedAt":"2011-01-06T21:04:38Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Phillip Susi wrote:\n\n> What I would like to do is be able to review a merge to sign off on it.\n>  While the full diff against the left parent would be a large and\n> unhelpful amalgamation of the changes in the merged branch, any\n> additional changes made during the commit should not be hidden.  This\n> allows someone performing the merge to effectively sneak in unintended\n> changes.  I would expect any such changes to be shown by log -p, but\n> this only seems to happen if you add -c.\n\nTo be more precise, here is what -c and --cc do.  Consider the\nfollowing history (time flowing left to right):\n\n    -- [topic]\n   /\n B --- [master]\n\n>From the master branch, I merge topic.  (1) If I am lucky, the changes\nfrom B to topic and B to master touch entirely different sections of\ncode (though perhaps within the same files), so one could just apply\nthe two diffs in succession to make a merge automatically.  (2) Almost\nas good is the case when they touch code a couple of lines apart ---\n\"git merge\" still figures it out automatically.  (3) Less nice is the\ncase when they touch the same line, say --- but even here the correct\nmerge can be obvious.  (4) Worst of all is when the changes\nsemantically conflict but syntactically do not:\n\n\t$ git merge topic\n\t$ make test;\t# fails!\n\t$ ... hack hack hack ...\n\t$ git commit --amend\n\n   -- o [topic] ------\n  /                   \\\n B -- o --------------- [master]\n\nIn case (1), -c will show a \"combined diff\" for files where master\ndoes not match either the old master or topic.  --cc, on the other\nhand, will correctly suppress these uninteresting diffs.\n\nIn case (2), -c will show a noisy \"combined diff\" as before.\n--cc will show a combined diff when the changes from both parents\ntouch nearby code, even if it merged trivially.\n\nIn case (3), -c and --cc will show the semantically boring but\nsyntactically interesting merge.\n\nCase (4) is underspecified.  So let's give a more precise example:\nthe old master and topic tried to fix the same bug in two incompatible\nways.  When merging, I decide I like the topic's way better, so I\nresolve conflicts in favor of the topic.  Hopefully all unrelated\nchanges on master were preserved!\n\nIn this case, -c and --cc will very likely show nothing at all.\nEach file matches one of the two parents (old master or topic) so\nthere is no easy way to distinguish the case from (0) or (1).\n\nBy now it should be clear how to get the diff you are looking for.\nOne makes a test merge, perhaps using the iffy \"resolve in favor\nof one side or the other\" feature to save time on conflicts:\n\n\tgit checkout oldmaster^0\n\tgit merge topic\n\tgit reset --merge ORIG_HEAD; # meh, too many conflicts\n\tgit merge -Xours topic\n\nand then makes a diff.\n\n\tgit diff master\n\nHope that helps,\nJonathan\n"},{"id":"159140","messageId":"4D276926.2020407@cfl.rr.com","threadId":"26216","inReplyTo":"20110106210438.GB15090@burratino","subject":"Re: log -p hides changes in merge commit","fromName":"Phillip Susi","fromEmail":"psusi@cfl.rr.com","sentAt":"2011-01-07T19:27:34Z","receivedAt":"2011-01-07T19:27:34Z","isPatch":false,"sender":{"key":"psusi@cfl.rr.com","avatar":null},"body":"On 1/6/2011 4:04 PM, Jonathan Nieder wrote:\n> In case (1), -c will show a \"combined diff\" for files where master\n> does not match either the old master or topic.  --cc, on the other\n> hand, will correctly suppress these uninteresting diffs.\n> \n> In case (2), -c will show a noisy \"combined diff\" as before.\n> --cc will show a combined diff when the changes from both parents\n> touch nearby code, even if it merged trivially.\n> \n> In case (3), -c and --cc will show the semantically boring but\n> syntactically interesting merge.\n> \n> Case (4) is underspecified.  So let's give a more precise example:\n> the old master and topic tried to fix the same bug in two incompatible\n> ways.  When merging, I decide I like the topic's way better, so I\n> resolve conflicts in favor of the topic.  Hopefully all unrelated\n> changes on master were preserved!\n> \n> In this case, -c and --cc will very likely show nothing at all.\n> Each file matches one of the two parents (old master or topic) so\n> there is no easy way to distinguish the case from (0) or (1).\n\nThat does help me understand the difference between -c and -cc, but I\nstill don't see why one or the other is not the default behavior of log\n-p, instead of opting to never show anything at all for merges?\n"},{"id":"159152","messageId":"7vk4ig5uib.fsf@alter.siamese.dyndns.org","threadId":"26216","inReplyTo":"4D276926.2020407@cfl.rr.com","subject":"Re: log -p hides changes in merge commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-01-07T20:27:56Z","receivedAt":"2011-01-07T20:27:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Susi <psusi@cfl.rr.com> writes:\n\n> That does help me understand the difference between -c and -cc, but I\n> still don't see why one or the other is not the default behavior of log\n> -p, instead of opting to never show anything at all for merges?\n\nAssuming this is about the default, the answer is very simple.  The\nfeatures to support -c and --cc came _much_ later than -p, and many people\nhave got used to the default behaviour after using \"log -p\" for a long\ntime.  It simply is rude to change the default on them.\n\nAs -c or --cc won't do anything special on a non-merge commit, you can\nalways say \"log -p --cc\" if that output is what you want to see.\n"}]}