{"thread":{"id":"40307","subject":"Re: Seeing git history of file including merge changes","startedAt":"2015-09-09T08:26:47Z","lastAt":"2015-09-09T09:04:27Z","messageCount":2,"participants":["Dov Grobgeld","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"269640","messageId":"CA++fsGHPEMhfENx-35=_9_k7mH98TU8NkHO0pYLC2aSxUKWvyg@mail.gmail.com","threadId":"40307","inReplyTo":"CA++fsGE-R1XpHxAVRZvOEAAwNr1XdTudGbwE4GYvg-E5L9kqEQ@mail.gmail.com","subject":"Re: Seeing git history of file including merge changes","fromName":"Dov Grobgeld","fromEmail":"dov.grobgeld@gmail.com","sentAt":"2015-09-09T08:26:47Z","receivedAt":"2015-09-09T08:26:47Z","isPatch":false,"sender":{"key":"dov.grobgeld@gmail.com","avatar":"https://gravatar.com/avatar/b74b57a9ce04ef5f356927856e125f1e70e7ce38772c5b8793b854b830f0fe6c?d=mp&s=160"},"body":"I asked the following question on StackOverflow a while ago, but did\nnot receive any answers so I'll try here.\n\nWe have git repository where a file was changed on a topic branch and\nthis branch was then merged back into the main branch. Due to various\nreasons the merge was made wrongly and as a result the changes were\nnot accepted during the merge. The following image shows what\nhappened:\n\n               -----\n              (  H  )\n               -----\n                 ^\n                 |\n                 |\n               -----\n              (  M  )\n               -----^\n                 ^   \\\n                 |    \\  -Delta\n                 |     \\\n                 |     -----\n                 |    (  B  )\n                 |     -----\n                 |    ^\n                 |   /  +Delta\n               -----/\n              (  A  )\n               -----\n\n\nThe file was changed in commit B and the changes were undone in commit M.\n\nMy problem is how to view the changes to the file between a specific\ncommit, e.g. B and another commit in its \"downstream\", e.g. H.\n\nIf you do\n\n    git log -u B..H\n\nyou won't see any changes, as the changes due to M are suppressed. You\ncan see potential changes by doing:\n\n    git log -u --full-history B..H\n\nwhich will show you that there was a merge commit, but it still won't\nshow you the diff between B and M.\n\nSo is there a way of seeing all changes made to a file including those\nmade by a merge commit?\n\nThanks!\n\nDov\n"},{"id":"269642","messageId":"20150909090427.GA21892@sigill.intra.peff.net","threadId":"40307","inReplyTo":"CA++fsGHPEMhfENx-35=_9_k7mH98TU8NkHO0pYLC2aSxUKWvyg@mail.gmail.com","subject":"Re: Seeing git history of file including merge changes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-09-09T09:04:27Z","receivedAt":"2015-09-09T09:04:27Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 09, 2015 at 11:26:47AM +0300, Dov Grobgeld wrote:\n\n> The file was changed in commit B and the changes were undone in commit M.\n> \n> My problem is how to view the changes to the file between a specific\n> commit, e.g. B and another commit in its \"downstream\", e.g. H.\n> \n> If you do\n> \n>     git log -u B..H\n> \n> you won't see any changes, as the changes due to M are suppressed. You\n> can see potential changes by doing:\n> \n>     git log -u --full-history B..H\n> \n> which will show you that there was a merge commit, but it still won't\n> show you the diff between B and M.\n> \n> So is there a way of seeing all changes made to a file including those\n> made by a merge commit?\n\nTry adding \"-m\". Normally for merges we show nothing, or the combined\ndiff. In the latter case, we consider a file which matches one of its\nparents to be an uninteresting change. From the perspective of walking\nback through history, as git-log does, it is impossible to know whether\nB made a change that was thrown away in the merge, or whether A made a\nchange that we kept. You can only know the answer by walking further\nback to the merge-base.\n\nUsing \"-m\" will show you the individual diff against each parent. But\nsince it is limited by the pathspec, it will show you only the diff\nagainst \"B\" in this case, which is what you want.  Using this recipe to\nrecreate your setup:\n\n    # a boring history with a file...\n    git init\n    echo base >file\n    git add file\n    git commit -m base\n    \n    # and some other commits...\n    echo foo >unrelated\n    git add unrelated\n    git commit -m unrelated\n    \n    # meanwhile, somebody forked from us and changed the file...\n    git checkout -b other HEAD^\n    echo change >>file && git commit -am change\n    \n    # now let's merge it in, undoing the change\n    git checkout master\n    git merge --no-commit other\n    echo base >file\n    git add file\n    git commit -m merged\n\nI get:\n\n    $ git log -p -m --full-history file\n    commit a279eccbb7cbb806dceff4591a1d4be74b060645 (from 36d29fbf1caf762ef2d78e484bfc1287a9df7603)\n    Merge: 2d1e518 36d29fb\n    Author: Jeff King <peff@peff.net>\n    Date:   Wed Sep 9 04:47:26 2015 -0400\n    \n        merged\n    \n    diff --git a/file b/file\n    index 09025f9..df967b9 100644\n    --- a/file\n    +++ b/file\n    @@ -1,2 +1 @@\n     base\n    -change\n\n    [...and so on, showing \"change\" and \"base\" as you'd expect]\n\nThat's pretty good, though if you had other merges in your log output, I\nexpect \"-m\" would be messy and confusing there.\n\nSo I think what you _really_ want is to recompute the original merge and\nshow something more clever. There is an old topic, tr/remerge-diff,\nwhich tried to do this. Its output looks the same as what is above, but\nit would probably do a better job of not making all of the _other_\nmerges look ugly.\n\nUnfortunately, development stalled on the topic, and it is nowhere close\nto being merged. I can dig up pointers if you'd like to play with it.\n\n-Peff\n"}]}