{"thread":{"id":"21427","subject":"finding the merge of two or more commits","startedAt":"2009-10-29T21:12:45Z","lastAt":"2009-10-30T23:38:12Z","messageCount":4,"participants":["E R","Avery Pennarun","Jeff King","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"126333","messageId":"3a69fa7c0910291412l439f7f61vd3b55a77cd7e10b5@mail.gmail.com","threadId":"21427","inReplyTo":null,"subject":"finding the merge of two or more commits","fromName":"E R","fromEmail":"pc88mxer@gmail.com","sentAt":"2009-10-29T21:12:45Z","receivedAt":"2009-10-29T21:12:45Z","isPatch":false,"sender":{"key":"pc88mxer@gmail.com","avatar":null},"body":"Hi,\n\nGiven two commits c1 and c2, is it possible to ask git if there are\nany commits in the repository that were created by either a sequence\nof commands like:\n\ngit checkout c1\ngit merge c2\n\nor:\n\ngit checkout c2\ngit merge c1\n\nwith any required conflict resolution?\n\nThat is, I don't want to merge c1 and c2 myself, but I want to know if\nsomeone else has merged c1 and c2, performed any conflict resolution\nand committed the result.\n\nThanks,\nER\n"},{"id":"126334","messageId":"32541b130910291434q1b068918x38c5aec543cb1c2a@mail.gmail.com","threadId":"21427","inReplyTo":"3a69fa7c0910291412l439f7f61vd3b55a77cd7e10b5@mail.gmail.com","subject":"Re: finding the merge of two or more commits","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2009-10-29T21:34:45Z","receivedAt":"2009-10-29T21:34:45Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On Thu, Oct 29, 2009 at 5:12 PM, E R <pc88mxer@gmail.com> wrote:\n> That is, I don't want to merge c1 and c2 myself, but I want to know if\n> someone else has merged c1 and c2, performed any conflict resolution\n> and committed the result.\n\nTry this:\n\n(git branch -a --contains c1; git branch -a --contains c2) | sort | uniq -d\n\nIt's not exactly pretty, but it works.\n\nHave fun,\n\nAvery\n"},{"id":"126401","messageId":"20091030180429.GD18583@coredump.intra.peff.net","threadId":"21427","inReplyTo":"32541b130910291434q1b068918x38c5aec543cb1c2a@mail.gmail.com","subject":"Re: finding the merge of two or more commits","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-30T18:04:29Z","receivedAt":"2009-10-30T18:04:29Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Oct 29, 2009 at 05:34:45PM -0400, Avery Pennarun wrote:\n\n> On Thu, Oct 29, 2009 at 5:12 PM, E R <pc88mxer@gmail.com> wrote:\n> > That is, I don't want to merge c1 and c2 myself, but I want to know if\n> > someone else has merged c1 and c2, performed any conflict resolution\n> > and committed the result.\n> \n> Try this:\n> \n> (git branch -a --contains c1; git branch -a --contains c2) | sort | uniq -d\n> \n> It's not exactly pretty, but it works.\n\nThat will tell you whether any branch contains both of them, which is\nnot exactly what the original poster asked for (though it may have been\nwhat he meant :) ). To see if there is a specific merge of those two\ncommits, you can do:\n\n  git log --all --format='%H %P' | grep \" $c1\" | grep \" $c2\" | cut -d' ' -f1\n\n-Peff\n"},{"id":"126456","messageId":"m3iqdwcv17.fsf@localhost.localdomain","threadId":"21427","inReplyTo":"3a69fa7c0910291412l439f7f61vd3b55a77cd7e10b5@mail.gmail.com","subject":"Re: finding the merge of two or more commits","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-10-30T23:38:12Z","receivedAt":"2009-10-30T23:38:12Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"E R <pc88mxer@gmail.com> writes:\n\n> Given two commits c1 and c2, is it possible to ask git if there are\n> any commits in the repository that were created by either a sequence\n> of commands like:\n> \n> git checkout c1\n> git merge c2\n> \n> or:\n> \n> git checkout c2\n> git merge c1\n> \n> with any required conflict resolution?\n> \n> That is, I don't want to merge c1 and c2 myself, but I want to know if\n> someone else has merged c1 and c2, performed any conflict resolution\n> and committed the result.\n\nI assume that commits c1 and c2 are not one ancestor of the other (are\nnot in fast-forward relation).\n\nTranslating your question into question about DAG of revisions, you\nwant to check if there is branch for which both c1 and c2 are\nreachable from:\n\n  c1sha=$(git rev-parse c1)\n  c2sha=$(git rev-parse c2)\n  git for-each-ref --format=\"%(refname)\" refs/heads/ |\n  while read refname\n  do \n      b1=$(git merge-base c1 $refname)\n      b2=$(git merge-base c2 $refname)\n      if [ \"$b1\" = \"$c1sha\" -a \"$b2\" = \"$c2sha\" ]\n      then\n          print ${refname#refs/heads/}\n      fi\n  done\n\nInstead of comparing git-merge-base with SHA-1 of c1 and c2\nrespoectively, you can count commits:\n\n  git for-each-ref --format=\"%(refname)\" refs/heads/ |\n  while read refname\n  do \n      count1=$(git rev-list c1..$refname | wc -l)\n      count2=$(git rev-list c2..$refname | wc -l)\n      if [ \"$count1\" > 0  -a  \"$count2\" > 0 ]\n      then\n          print ${refname#refs/heads/}\n      fi\n  done\n\nNot tested!\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}