{"thread":{"id":"14589","subject":"How to find the first commit belonging to any branch","startedAt":"2008-07-22T09:08:47Z","lastAt":"2008-07-22T11:18:09Z","messageCount":3,"participants":["Kristian Amlie","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"84309","messageId":"4885A39F.5080209@trolltech.com","threadId":"14589","inReplyTo":null,"subject":"How to find the first commit belonging to any branch","fromName":"Kristian Amlie","fromEmail":"kristian.amlie@trolltech.com","sentAt":"2008-07-22T09:08:47Z","receivedAt":"2008-07-22T09:08:47Z","isPatch":false,"sender":{"key":"kristian.amlie@trolltech.com","avatar":null},"body":"Hi all!\n\nI have a question about git: I have one commit sha1, and I would like to \nknow the nearest commit that appears in *any* other branch. The sha1 \nthat I have does not belong to any branch.\n\nThe obvious thing to do would be to make a for loop and iterate over \nexisting branches while calling git merge-base, but I'm wondering if \nthere's a more clever method.\n\nRegards\nKristian Amlie\n"},{"id":"84313","messageId":"7vej5mmfp9.fsf@gitster.siamese.dyndns.org","threadId":"14589","inReplyTo":"4885A39F.5080209@trolltech.com","subject":"Re: How to find the first commit belonging to any branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-07-22T09:27:30Z","receivedAt":"2008-07-22T09:27:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kristian Amlie <kristian.amlie@trolltech.com> writes:\n\n> I have a question about git: I have one commit sha1, and I would like\n> to know the nearest commit that appears in *any* other branch. The\n> sha1 that I have does not belong to any branch.\n>\n> The obvious thing to do would be to make a for loop and iterate over\n> existing branches while calling git merge-base, but I'm wondering if\n> there's a more clever method.\n\nIf the $commit does not belong to any branch, then:\n\n    $ git rev-list --bounardy $commit^0 --not --branches | sed -ne 's/^-//p'\n\nwould give you boundary commits of the above traversal, which says:\n\n    Traverse from $commit following the parents, but stop at anything that\n    is reachable from any breanch.\n\nwhich means that the ones that are output are the candidates that are on\nsome branch.\n\nSo pipe that to name-rev like this, perhaps (untested)?\n\n    $ git rev-list --bounardy $commit^0 --not --branches |\n      sed -ne 's/^-//p' |\n      git name-rev --stdin\n"},{"id":"84321","messageId":"4885C1F1.7060907@trolltech.com","threadId":"14589","inReplyTo":"7vej5mmfp9.fsf@gitster.siamese.dyndns.org","subject":"Re: How to find the first commit belonging to any branch","fromName":"Kristian Amlie","fromEmail":"kristian.amlie@trolltech.com","sentAt":"2008-07-22T11:18:09Z","receivedAt":"2008-07-22T11:18:09Z","isPatch":false,"sender":{"key":"kristian.amlie@trolltech.com","avatar":null},"body":"Junio C Hamano wrote:\n> Kristian Amlie <kristian.amlie@trolltech.com> writes:\n> \n>> I have a question about git: I have one commit sha1, and I would like\n>> to know the nearest commit that appears in *any* other branch. The\n>> sha1 that I have does not belong to any branch.\n>>\n>> The obvious thing to do would be to make a for loop and iterate over\n>> existing branches while calling git merge-base, but I'm wondering if\n>> there's a more clever method.\n> \n> If the $commit does not belong to any branch, then:\n> \n>     $ git rev-list --bounardy $commit^0 --not --branches | sed -ne 's/^-//p'\n> \n> would give you boundary commits of the above traversal, which says:\n> \n>     Traverse from $commit following the parents, but stop at anything that\n>     is reachable from any breanch.\n> \n> which means that the ones that are output are the candidates that are on\n> some branch.\n> \n> So pipe that to name-rev like this, perhaps (untested)?\n> \n>     $ git rev-list --bounardy $commit^0 --not --branches |\n>       sed -ne 's/^-//p' |\n>       git name-rev --stdin\n> \n> \n\nThanks! That did the trick!\n\nKristian\n"}]}