{"thread":{"id":"3267","subject":"Shortest path between commits","startedAt":"2006-02-08T16:03:08Z","lastAt":"2006-02-08T16:43:50Z","messageCount":2,"participants":["Ralf Baechle","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"15715","messageId":"20060208160308.GB3484@linux-mips.org","threadId":"3267","inReplyTo":null,"subject":"Shortest path between commits","fromName":"Ralf Baechle","fromEmail":"ralf@linux-mips.org","sentAt":"2006-02-08T16:03:08Z","receivedAt":"2006-02-08T16:03:08Z","isPatch":false,"sender":{"key":"ralf@linux-mips.org","avatar":null},"body":"I wonder if there some way to find the shortest path between two commits?\nThat is if there is a merge between the two commits I only want the merge\ncommit itself, not the potencially large list of commits that were merged.\n\nI need that for commit notification scripts; I don't want to spam users\nwith too many emails and aggregating everything that came through a single\nmerge would be a reaonsable approach.\n\n  Ralf\n"},{"id":"15719","messageId":"Pine.LNX.4.64.0602080834490.2458@g5.osdl.org","threadId":"3267","inReplyTo":"20060208160308.GB3484@linux-mips.org","subject":"Re: Shortest path between commits","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-02-08T16:43:50Z","receivedAt":"2006-02-08T16:43:50Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 8 Feb 2006, Ralf Baechle wrote:\n>\n> I wonder if there some way to find the shortest path between two commits?\n> That is if there is a merge between the two commits I only want the merge\n> commit itself, not the potencially large list of commits that were merged.\n\nThe problem is that it's entirely possible that no such path even \nexists.\n\nTwo commits are not necessarily directly related, and asking for the \nshortest path may involve having to go both backwards _and_ forwards in \nhistory to get from one to the other. The most trivial case is\n\n\t    a  <- head of tree\n\t   / \\\n\t  /   \\\n\t b     c\n\t  \\   /\n\t   \\ /\n\t    d  <- root\n\nwhere the shortest path between \"b\" and \"c\" is not really a well-defined \nnotion.\n\nNow, _if_ you know that one of the commits is a direct descendant of the \nother, a sensible path can be decided on, but even then the notion of \n\"shortest\" is not obvious. Look at \"a\" vs \"d\" above - which path is the \nshortest one? The one through \"b\" or the one through \"c\"? There's really \nno way to tell them apart (you could select \"first parent\", but in more \ncomplex graphs that might not be unambiguous either).\n\nThat said, and to finally answer your question: selecing _one_ short path \nbetween two commits (if they are directly related) is certainly possible, \nbut no, we don't have anything like that available right now. It wouldn't \nbe hugely difficult to do an addition to git-rev-list to do so, though.\n\nCan you describe your usage case? The operation really _isn't_ sensible in \ngeneral, so while I could add a flag to git-rev-list to only print out as \ndirect a chain as possible, I'd like to know that there is at least _one_ \nentirely sane usage for such a thing.\n\n\t\tLinus\n"}]}