{"thread":{"id":"17377","subject":"Common ancestor in merge diffs?","startedAt":"2009-01-26T18:41:41Z","lastAt":"2009-01-26T20:54:31Z","messageCount":7,"participants":["Daniel Barkalow","Johannes Schindelin","Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"102017","messageId":"alpine.LNX.1.00.0901261318030.19665@iabervon.org","threadId":"17377","inReplyTo":null,"subject":"Common ancestor in merge diffs?","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-01-26T18:41:41Z","receivedAt":"2009-01-26T18:41:41Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"I was just doing an annoying merge (I'd reorganized code while other \npeople made changes to it), and I kept having the problem that it was hard \nto figure out what each side had done. Is there some way to ask git for \nthe diffs between the common ancestor (which is unique in my case, so it's \nactually useful) and each of the sides of the merge? Ideally, it would \ngive essentially the converse of the --cc diff: first column is -stage 1 \n+stage 2; second column is -stage 1 +stage 3.\n\nI think this would generally be more useful than the current diff output \nfor the unresolved portions (-stage 3 +working tree, -stage 2 +working \ntree) because you're generally quite familiar with the working tree (since \nyou're trying to resolve there), and stage 1 is not obvious.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"102020","messageId":"alpine.DEB.1.00.0901261958320.25749@intel-tinevez-2-302","threadId":"17377","inReplyTo":"alpine.LNX.1.00.0901261318030.19665@iabervon.org","subject":"Re: Common ancestor in merge diffs?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-26T18:59:07Z","receivedAt":"2009-01-26T18:59:07Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 26 Jan 2009, Daniel Barkalow wrote:\n\n> I was just doing an annoying merge (I'd reorganized code while other \n> people made changes to it), and I kept having the problem that it was hard \n> to figure out what each side had done. Is there some way to ask git for \n> the diffs between the common ancestor (which is unique in my case, so it's \n> actually useful) and each of the sides of the merge?\n\nHow about\n\n\tgit diff HEAD...MERGE_HEAD\n\nand\n\n\tgit diff MERGE_HEAD...HEAD\n\n?  I might have misunderstood, though.\n\nCiao,\nDscho\n"},{"id":"102023","messageId":"alpine.LFD.2.00.0901261100200.5284@localhost.localdomain","threadId":"17377","inReplyTo":"alpine.LNX.1.00.0901261318030.19665@iabervon.org","subject":"Re: Common ancestor in merge diffs?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-01-26T19:05:12Z","receivedAt":"2009-01-26T19:05:12Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 26 Jan 2009, Daniel Barkalow wrote:\n>\n> I was just doing an annoying merge (I'd reorganized code while other \n> people made changes to it), and I kept having the problem that it was hard \n> to figure out what each side had done. Is there some way to ask git for \n> the diffs between the common ancestor (which is unique in my case, so it's \n> actually useful) and each of the sides of the merge? Ideally, it would \n> give essentially the converse of the --cc diff: first column is -stage 1 \n> +stage 2; second column is -stage 1 +stage 3.\n\nHave you tried \"gitk --merge [filename]\"?\n\nThat's usually even more useful - because it doesn't just give a diff, it \ngives the actual commits that caused the conflict. That way you see what \nboth sides of a merge tried to do.. It's what I do when encountering \nconflicts on the kernel (where I'm usually not the author of _either_ side \nof the code that causes a conflict), and it really is very powerful.\n\nThat said, finding the diffs from the common case is pretty trivial too. \nJust do\n\n\tgit diff MERGE_HEAD...HEAD [filename]\n\nand you'll get the diff from the common case to the HEAD, and if you \nswitch them around, you'll get the diff from the common commit to the \nMERGE_HEAD. Note the _three_ dots.\n\n\t\t\tLinus\n"},{"id":"102024","messageId":"alpine.LNX.1.00.0901261402120.19665@iabervon.org","threadId":"17377","inReplyTo":"alpine.DEB.1.00.0901261958320.25749@intel-tinevez-2-302","subject":"Re: Common ancestor in merge diffs?","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-01-26T19:06:48Z","receivedAt":"2009-01-26T19:06:48Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Mon, 26 Jan 2009, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Mon, 26 Jan 2009, Daniel Barkalow wrote:\n> \n> > I was just doing an annoying merge (I'd reorganized code while other \n> > people made changes to it), and I kept having the problem that it was hard \n> > to figure out what each side had done. Is there some way to ask git for \n> > the diffs between the common ancestor (which is unique in my case, so it's \n> > actually useful) and each of the sides of the merge?\n> \n> How about\n> \n> \tgit diff HEAD...MERGE_HEAD\n> \n> and\n> \n> \tgit diff MERGE_HEAD...HEAD\n> \n> ?  I might have misunderstood, though.\n\nThat's definitely helpful information (and I'd forgotten about it; I was \nonly thinking of the index). It would be helpful to get it in --cc form, \nthough, rather than as two independant diffs. And it seems somewhat \nwasteful or something to not use the information in the index, although \nit's hard to get worked up about with git being blindingly fast anyway.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"102032","messageId":"alpine.LNX.1.00.0901261412110.19665@iabervon.org","threadId":"17377","inReplyTo":"alpine.LFD.2.00.0901261100200.5284@localhost.localdomain","subject":"Re: Common ancestor in merge diffs?","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-01-26T19:52:34Z","receivedAt":"2009-01-26T19:52:34Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Mon, 26 Jan 2009, Linus Torvalds wrote:\n\n> On Mon, 26 Jan 2009, Daniel Barkalow wrote:\n> >\n> > I was just doing an annoying merge (I'd reorganized code while other \n> > people made changes to it), and I kept having the problem that it was hard \n> > to figure out what each side had done. Is there some way to ask git for \n> > the diffs between the common ancestor (which is unique in my case, so it's \n> > actually useful) and each of the sides of the merge? Ideally, it would \n> > give essentially the converse of the --cc diff: first column is -stage 1 \n> > +stage 2; second column is -stage 1 +stage 3.\n> \n> Have you tried \"gitk --merge [filename]\"?\n> \n> That's usually even more useful - because it doesn't just give a diff, it \n> gives the actual commits that caused the conflict. That way you see what \n> both sides of a merge tried to do.. It's what I do when encountering \n> conflicts on the kernel (where I'm usually not the author of _either_ side \n> of the code that causes a conflict), and it really is very powerful.\n\nThat is really nice, and quite handy. I ended up getting approximately \nthat effect with blame and show, but gitk is much easier. For some reason, \nI never think of the graphical tools. Is there an easy way of focusing on \nthe changes that end up in a particular conflict? Half of the work was \nfinding the right commit and finding the right part of the diff.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"102034","messageId":"7vhc3l6dvx.fsf@gitster.siamese.dyndns.org","threadId":"17377","inReplyTo":"alpine.LNX.1.00.0901261318030.19665@iabervon.org","subject":"Re: Common ancestor in merge diffs?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-26T19:55:30Z","receivedAt":"2009-01-26T19:55:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> I was just doing an annoying merge (I'd reorganized code while other \n> people made changes to it), and I kept having the problem that it was hard \n> to figure out what each side had done. Is there some way to ask git for \n> the diffs between the common ancestor (which is unique in my case, so it's \n> actually useful) and each of the sides of the merge?\n\nHave you tried \"git checkout --conflict=diff3 $that_conflicted_path\"?\n"},{"id":"102046","messageId":"alpine.LFD.2.00.0901261241540.3465@localhost.localdomain","threadId":"17377","inReplyTo":"alpine.LNX.1.00.0901261412110.19665@iabervon.org","subject":"Re: Common ancestor in merge diffs?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-01-26T20:54:31Z","receivedAt":"2009-01-26T20:54:31Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 26 Jan 2009, Daniel Barkalow wrote:\n> \n> That is really nice, and quite handy. I ended up getting approximately \n> that effect with blame and show, but gitk is much easier. For some reason, \n> I never think of the graphical tools.\n\nYou can do the same thing on the command-line with just doing\n\n\tgit log --merge [filename]\n\nbut when doing conflict resolution you often do care (deeply) about the \nway the commits hang together, so the graphical tools really do end up \ngiving you fundamentally interesting information that is hard to show in \nany readable way with just plain text.\n\n[ Yeah, there's \"--graph\", but it really loses out on the whole \n  readability thing ]\n\n> Is there an easy way of focusing on the changes that end up in a \n> particular conflict? Half of the work was finding the right commit and \n> finding the right part of the diff.\n\nThis is where the command line tools really help. What I do is to just \nfire up that \"gitk\" and 90% of the time the thing is clear from that. But \n_if_ it then is complex, and has a ton of changes to the same file that \nreally aren't that interesting, doing a \n\n\tgit log --merge -S'interesting-part-goes-here' [filename]\n\nin another window tends to be a good idea. That way you get the commits \nthat just touch that string, and you can do the whole 'goto-SHA1' in the \ngitk window to see them there.\n\nSometimes, \"git blame -C \" is also a good tool to have around. You seem to \nhave found it already. One usage case is\n\n\tgit blame -C $(git merge-base HEAD MERGE_HEAD).. filename\n\nwhich then high-lights the lines changed from the merge-base to the HEAD \n(change it to \"..MERGE_HEAD\" to see what changed to MERGE_HEAD), but quite \nfrankly, I tend to use \"git blame\" more as a tool _after_ the merge, when \nI noticed that I merged things wrong and go back and try to figure out \nwhat caused the problem.\n\n\t\tLinus\n"}]}