{"thread":{"id":"12790","subject":"How to find where a branch was taken from.","startedAt":"2008-03-21T09:05:39Z","lastAt":"2008-03-22T16:54:56Z","messageCount":12,"participants":["Paul Gardiner","Junio C Hamano","Avery Pennarun","Charles Bailey","Dmitry Potapov","Daniel Barkalow","J. Bruce Fields","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"72584","messageId":"47E37A63.9070209@glidos.net","threadId":"12790","inReplyTo":null,"subject":"How to find where a branch was taken from.","fromName":"Paul Gardiner","fromEmail":"osronline@glidos.net","sentAt":"2008-03-21T09:05:39Z","receivedAt":"2008-03-21T09:05:39Z","isPatch":false,"sender":{"key":"osronline@glidos.net","avatar":null},"body":"I need a command that will find the remote branch from which\nthe currently checked out branch was started. I don't know\ngit very well, and the only way I can think to do it so far\nis to iterate over the remote branches and find the one\nfor which git-rev-list <branch>..HEAD gives the smallest\nnumber of objects. I'm guessing there must be a better\nway. Any ideas?\n\nCheers,\n\tPaul.\n"},{"id":"72585","messageId":"7v4pb0qw28.fsf@gitster.siamese.dyndns.org","threadId":"12790","inReplyTo":"47E37A63.9070209@glidos.net","subject":"Re: How to find where a branch was taken from.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-21T09:13:19Z","receivedAt":"2008-03-21T09:13:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paul Gardiner <osronline@glidos.net> writes:\n\n> I need a command that will find the remote branch from which\n> the currently checked out branch was started. I don't know\n> git very well, and the only way I can think to do it so far\n> is to iterate over the remote branches and find the one\n> for which git-rev-list <branch>..HEAD gives the smallest\n> number of objects. I'm guessing there must be a better\n> way. Any ideas?\n\nThere will be _no_ way.  It is simply impossible.\n\n    $ git checkout -b my-new-branch origin/somerandombranch~27^2^2~23\n\nis a perfectly valid way to create a new branch.\n\nYou would probably want to re-think in a bigger picture, _why_\nyou would want to find such information, in other words, how you would\nwant to use the information (if such a thing were possible) to solve\n_what_ problem.  That true problem you did not mention (and assumed that\n\"the remote branch the branch was branched from\" would be a good tool to\nsolve it) might have a better solution.\n"},{"id":"72586","messageId":"7vzlssphdn.fsf@gitster.siamese.dyndns.org","threadId":"12790","inReplyTo":"7v4pb0qw28.fsf@gitster.siamese.dyndns.org","subject":"Re: How to find where a branch was taken from.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-21T09:15:48Z","receivedAt":"2008-03-21T09:15:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Paul Gardiner <osronline@glidos.net> writes:\n>\n>> I need a command that will find the remote branch from which\n>> the currently checked out branch was started. I don't know\n>> git very well, and the only way I can think to do it so far\n>> is to iterate over the remote branches and find the one\n>> for which git-rev-list <branch>..HEAD gives the smallest\n>> number of objects. I'm guessing there must be a better\n>> way. Any ideas?\n>\n> There will be _no_ way.  It is simply impossible.\n>\n>     $ git checkout -b my-new-branch origin/somerandombranch~27^2^2~23\n>\n> is a perfectly valid way to create a new branch.\n>\n> You would probably want to re-think in a bigger picture, _why_\n> you would want to find such information, in other words, how you would\n> want to use the information (if such a thing were possible) to solve\n> _what_ problem.  That true problem you did not mention (and assumed that\n> \"the remote branch the branch was branched from\" would be a good tool to\n> solve it) might have a better solution.\n\nHaving said that, have you tried:\n\n\t$ git reflog show that_local_branch\n\nand looked for \"branch: Created from blah\"?\n"},{"id":"72603","messageId":"32541b130803211039h1f5b8da5k8fb353d46e57b05e@mail.gmail.com","threadId":"12790","inReplyTo":"7v4pb0qw28.fsf@gitster.siamese.dyndns.org","subject":"Re: How to find where a branch was taken from.","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2008-03-21T17:39:11Z","receivedAt":"2008-03-21T17:39:11Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On Fri, Mar 21, 2008 at 5:13 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Paul Gardiner <osronline@glidos.net> writes:\n>  > I need a command that will find the remote branch from which\n>  > the currently checked out branch was started. I don't know\n>  > git very well, and the only way I can think to do it so far\n>  > is to iterate over the remote branches and find the one\n>  > for which git-rev-list <branch>..HEAD gives the smallest\n>  > number of objects. I'm guessing there must be a better\n>  > way. Any ideas?\n>\n>  There will be _no_ way.  It is simply impossible.\n>\n>     $ git checkout -b my-new-branch origin/somerandombranch~27^2^2~23\n>\n>  is a perfectly valid way to create a new branch.\n>\n>  You would probably want to re-think in a bigger picture, _why_\n>  you would want to find such information, [...]\n\nI frequently want to do this.  Basically, I start from \"some version\"\nof the upstream program, and I put together some patches, then I want\nto use rebase to reorder and recombine them before I send them in.\n\nIn order to do this, however, I'm forced to remember where I got my\n\"original\" version from, which isn't even that important.  As the\ndeveloper of a particular patch, all I *really* should have to know\nis: a) here are the things I added since I made my topic branch, and\nb) here is the branch I want to rebase them onto so I can submit my\ncleaned patches upstream.\n\nIf git would explicitly track the rev at which my branch was created,\nit would mostly solve *my* problem here, even though I wouldn't know\nthe *name* of the branch I branched from.\n\nAlternatively, we could avoid tracking anything extra at all.  If git\ncould suggest a branch or tag that mine is \"currently closest to\",\nie., the one that has as many of the commits from my branch as\npossible (even if it has additional commits that I don't have), then\nthat might be the branch I'm interested in.  If not, I could use this\ncomment repeatedly to produce a \"chain of parent branches\", one of\nwhich is probably the one I'm interested in.\n\nHave fun,\n\nAvery\n"},{"id":"72608","messageId":"20080321183225.GA13583@hashpling.org","threadId":"12790","inReplyTo":"32541b130803211039h1f5b8da5k8fb353d46e57b05e@mail.gmail.com","subject":"Re: How to find where a branch was taken from.","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2008-03-21T18:32:25Z","receivedAt":"2008-03-21T18:32:25Z","isPatch":false,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"On Fri, Mar 21, 2008 at 01:39:11PM -0400, Avery Pennarun wrote:\n> On Fri, Mar 21, 2008 at 5:13 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> > Paul Gardiner <osronline@glidos.net> writes:\n> >  > I need a command that will find the remote branch from which\n> >  > the currently checked out branch was started. I don't know\n> >  > git very well, and the only way I can think to do it so far\n> >  > is to iterate over the remote branches and find the one\n> >  > for which git-rev-list <branch>..HEAD gives the smallest\n> >  > number of objects. I'm guessing there must be a better\n> >  > way. Any ideas?\n> >\n> >  There will be _no_ way.  It is simply impossible.\n> >\n> >     $ git checkout -b my-new-branch origin/somerandombranch~27^2^2~23\n> >\n> >  is a perfectly valid way to create a new branch.\n> >\n> >  You would probably want to re-think in a bigger picture, _why_\n> >  you would want to find such information, [...]\n> \n> I frequently want to do this.  Basically, I start from \"some version\"\n> of the upstream program, and I put together some patches, then I want\n> to use rebase to reorder and recombine them before I send them in.\n\nSo you're looking to do a git rebase -i?\n\n> In order to do this, however, I'm forced to remember where I got my\n> \"original\" version from, which isn't even that important.  As the\n> developer of a particular patch, all I *really* should have to know\n> is: a) here are the things I added since I made my topic branch, and\n> b) here is the branch I want to rebase them onto so I can submit my\n> cleaned patches upstream.\n\nWhy are you forced to remember?\n\nIf you don't want to transplant the patches onto where the remote\nbranch is now, then you just need to pick a commit on your current\nbranch that is before any commit that you want to reorder/recombine\nand do a git rebase -i <sha1>. (It should be easy to pick a commit\nfrom git log. Perhaps it's the first one with and author that isn't\nyou.  Alternatively, if you don't want to look at the log and you know\nyou haven't made more than N commits you could just git rebase -i\nHEAD~N.)\n\nIf you want to rebase them on to the latest version of the remote\nbranch then it's even simpler. You just do:\n\ngit rebase -i remote/branch\n\nI'm not sure I understand why you need to know where your original\nbranch was made from?\n\nCharles.\n"},{"id":"72611","messageId":"32541b130803211148r651d03eev98a478b13e69f710@mail.gmail.com","threadId":"12790","inReplyTo":"20080321183225.GA13583@hashpling.org","subject":"Re: How to find where a branch was taken from.","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2008-03-21T18:48:28Z","receivedAt":"2008-03-21T18:48:28Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On Fri, Mar 21, 2008 at 2:32 PM, Charles Bailey <charles@hashpling.org> wrote:\n>  > In order to do this, however, I'm forced to remember where I got my\n>  > \"original\" version from, which isn't even that important.  As the\n>  > developer of a particular patch, all I *really* should have to know\n>  > is: a) here are the things I added since I made my topic branch, and\n>  > b) here is the branch I want to rebase them onto so I can submit my\n>  > cleaned patches upstream.\n>\n>  Why are you forced to remember?\n>\n>  If you don't want to transplant the patches onto where the remote\n>  branch is now, then you just need to pick a commit on your current\n>  branch that is before any commit that you want to reorder/recombine\n>  and do a git rebase -i <sha1>. (It should be easy to pick a commit\n>  from git log. Perhaps it's the first one with and author that isn't\n>  you.  [...]\n\nAll these things work, but they're unnecessarily tedious manual\nremembering.  If I have a lot of topic branches on the go at once,\nthings start getting a little messy and it's hard to remember which\npatches came from where, particularly if I'm aggregating, reviewing,\nand cleaning up patches from several people at work before sending\nthem upstream (in which case I don't always recognize the checkin\nmessages presented in git-rebase -i).\n\nsvn has \"svn log --stop-on-copy\", which is useful in exactly this\nsituation.  A git branch is not really a \"copy\", of course, so the\nactual implementation can't be the same.\n\n\"git show-branch\" has logic very close to what we need here: if you\ngive it the names of your current branch and its parent, it'll show\nyou just the changes on both branches since the branchpoint.  But I\ndon't really want to know about additional changes on the parent, only\non the branch I'm working with, and I often prefer the output to be in\ngit-log's (very flexible) format instead of git-show-branch.\n\nHave fun,\n\nAvery\n"},{"id":"72618","messageId":"37fcd2780803211303r1a247739na79e78c609565010@mail.gmail.com","threadId":"12790","inReplyTo":"32541b130803211148r651d03eev98a478b13e69f710@mail.gmail.com","subject":"Re: How to find where a branch was taken from.","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2008-03-21T20:03:18Z","receivedAt":"2008-03-21T20:03:18Z","isPatch":false,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"On Fri, Mar 21, 2008 at 9:48 PM, Avery Pennarun <apenwarr@gmail.com> wrote:\n>\n>  \"git show-branch\" has logic very close to what we need here: if you\n>  give it the names of your current branch and its parent, it'll show\n>  you just the changes on both branches since the branchpoint.  But I\n>  don't really want to know about additional changes on the parent, only\n>  on the branch I'm working with, and I often prefer the output to be in\n>  git-log's (very flexible) format instead of git-show-branch.\n\nI believe that\n\n   git log parent-branch..local-branch\n\nshould give you exactly what you want, i.e. all changes on your local\nbranch since it was copied from the parent branch.\n\nDmitry\n"},{"id":"72619","messageId":"alpine.LNX.1.00.0803211618150.19665@iabervon.org","threadId":"12790","inReplyTo":"37fcd2780803211303r1a247739na79e78c609565010@mail.gmail.com","subject":"Re: How to find where a branch was taken from.","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-03-21T20:22:11Z","receivedAt":"2008-03-21T20:22:11Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Fri, 21 Mar 2008, Dmitry Potapov wrote:\n\n> On Fri, Mar 21, 2008 at 9:48 PM, Avery Pennarun <apenwarr@gmail.com> wrote:\n> >\n> >  \"git show-branch\" has logic very close to what we need here: if you\n> >  give it the names of your current branch and its parent, it'll show\n> >  you just the changes on both branches since the branchpoint.  But I\n> >  don't really want to know about additional changes on the parent, only\n> >  on the branch I'm working with, and I often prefer the output to be in\n> >  git-log's (very flexible) format instead of git-show-branch.\n> \n> I believe that\n> \n>    git log parent-branch..local-branch\n> \n> should give you exactly what you want, i.e. all changes on your local\n> branch since it was copied from the parent branch.\n\nThen you need to remember what the parent branch was. But:\n\n  git log local-branch ^maybe-parent-1 ^maybe-parent-2 ...\n\nshould give you what you want.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"72620","messageId":"20080321202505.GG29086@fieldses.org","threadId":"12790","inReplyTo":"alpine.LNX.1.00.0803211618150.19665@iabervon.org","subject":"Re: How to find where a branch was taken from.","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2008-03-21T20:25:05Z","receivedAt":"2008-03-21T20:25:05Z","isPatch":false,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Fri, Mar 21, 2008 at 04:22:11PM -0400, Daniel Barkalow wrote:\n> On Fri, 21 Mar 2008, Dmitry Potapov wrote:\n> \n> > On Fri, Mar 21, 2008 at 9:48 PM, Avery Pennarun <apenwarr@gmail.com> wrote:\n> > >\n> > >  \"git show-branch\" has logic very close to what we need here: if you\n> > >  give it the names of your current branch and its parent, it'll show\n> > >  you just the changes on both branches since the branchpoint.  But I\n> > >  don't really want to know about additional changes on the parent, only\n> > >  on the branch I'm working with, and I often prefer the output to be in\n> > >  git-log's (very flexible) format instead of git-show-branch.\n> > \n> > I believe that\n> > \n> >    git log parent-branch..local-branch\n> > \n> > should give you exactly what you want, i.e. all changes on your local\n> > branch since it was copied from the parent branch.\n> \n> Then you need to remember what the parent branch was. But:\n> \n>   git log local-branch ^maybe-parent-1 ^maybe-parent-2 ...\n> \n> should give you what you want.\n\nhttp://www.kernel.org/pub/software/scm/git/docs/user-manual.html#showing-commits-unique-to-a-branch\n\nalso has a couple amusing examples along these lines.\n\n--b.\n"},{"id":"72653","messageId":"47E4F7A0.6060702@glidos.net","threadId":"12790","inReplyTo":"32541b130803211039h1f5b8da5k8fb353d46e57b05e@mail.gmail.com","subject":"Re: How to find where a branch was taken from.","fromName":"Paul Gardiner","fromEmail":"osronline@glidos.net","sentAt":"2008-03-22T12:12:16Z","receivedAt":"2008-03-22T12:12:16Z","isPatch":false,"sender":{"key":"osronline@glidos.net","avatar":null},"body":"Avery Pennarun wrote:\n> Alternatively, we could avoid tracking anything extra at all.  If git\n> could suggest a branch or tag that mine is \"currently closest to\",\n> ie., the one that has as many of the commits from my branch as\n> possible (even if it has additional commits that I don't have), then\n> that might be the branch I'm interested in.\n\nYes, that's exactly what I need too. I need to produce it\nprogramatically. I notice gitk displays, for each commit,\nthe branches that include it. If I knew a command for\nderiving that, I could iterate through HEAD, HEAD~1, HEAD~2...\nuntil I see a remote branch.\n\nP.\n"},{"id":"72676","messageId":"20080322164136.GA7611@coredump.intra.peff.net","threadId":"12790","inReplyTo":"47E4F7A0.6060702@glidos.net","subject":"Re: How to find where a branch was taken from.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-22T16:41:37Z","receivedAt":"2008-03-22T16:41:37Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Mar 22, 2008 at 12:12:16PM +0000, Paul Gardiner wrote:\n\n> Yes, that's exactly what I need too. I need to produce it\n> programatically. I notice gitk displays, for each commit,\n> the branches that include it. If I knew a command for\n> deriving that, I could iterate through HEAD, HEAD~1, HEAD~2...\n> until I see a remote branch.\n\nHow about:\n\n  git name-rev --refs='refs/remotes/*' $COMMIT\n\n?\n\n-Peff\n"},{"id":"72677","messageId":"47E539E0.3030701@glidos.net","threadId":"12790","inReplyTo":"20080322164136.GA7611@coredump.intra.peff.net","subject":"Re: How to find where a branch was taken from.","fromName":"Paul Gardiner","fromEmail":"osronline@glidos.net","sentAt":"2008-03-22T16:54:56Z","receivedAt":"2008-03-22T16:54:56Z","isPatch":false,"sender":{"key":"osronline@glidos.net","avatar":null},"body":"Jeff King wrote:\n> On Sat, Mar 22, 2008 at 12:12:16PM +0000, Paul Gardiner wrote:\n> \n>> Yes, that's exactly what I need too. I need to produce it\n>> programatically. I notice gitk displays, for each commit,\n>> the branches that include it. If I knew a command for\n>> deriving that, I could iterate through HEAD, HEAD~1, HEAD~2...\n>> until I see a remote branch.\n> \n> How about:\n> \n>   git name-rev --refs='refs/remotes/*' $COMMIT\n\nWow! That's clever.\n\nThanks,\n\tPaul.\n"}]}