{"thread":{"id":"17454","subject":"Finding the name of the parent branch?","startedAt":"2009-01-30T10:56:12Z","lastAt":"2009-01-30T15:58:39Z","messageCount":11,"participants":["Pascal Obry","Santi Béjar","Michael J Gruber","Thomas Koch"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"102563","messageId":"a2633edd0901300256k2ad7530elcaca5cdc30c17534@mail.gmail.com","threadId":"17454","inReplyTo":null,"subject":"Finding the name of the parent branch?","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2009-01-30T10:56:12Z","receivedAt":"2009-01-30T10:56:12Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"I want to find the name of the parent branch in a script. What is the best way?\n\n                         o---o---o---C\n                         /\n                    o---o---o---B\n                   /\n           ---o---o---o---o---o---A\n\nFor B I want to get A and for C I want to get B.\n\nAll this can be found in gitk, but from a script I did not found a\ngood solution.\n\nAny idea?\n\nThanks.\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"102570","messageId":"adf1fd3d0901300318s5a0e4c94gab5f31342643ea52@mail.gmail.com","threadId":"17454","inReplyTo":"a2633edd0901300256k2ad7530elcaca5cdc30c17534@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-01-30T11:18:39Z","receivedAt":"2009-01-30T11:18:39Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/1/30 Pascal Obry <pascal@obry.net>:\n> I want to find the name of the parent branch in a script. What is the best way?\n>\n>                         o---o---o---C\n>                         /\n>                    o---o---o---B\n>                   /\n>           ---o---o---o---o---o---A\n>\n> For B I want to get A and for C I want to get B.\n\nI think your definition is not well defined. A, B and C are just\nbranches of you project, technically they are equivalent. Maybe you\nare thinking that the common commits of, say A and B, really belongs\nto A, but this is not the case they belong to both branches. In git a\nbranch is really just a pointer to a commit and by extension the\nhistory, it is not a series of commits.\n\nJust a counterexample, just rearranging you graph:\n\n                        o---B\n                        /\n                   o---o---o---o---o---C\n                  /\n          ---o---o---o---o---o---A\n\n>From you description: For B I would get C and for C I would get A.\n\nHTH,\nSanti\n"},{"id":"102579","messageId":"a2633edd0901300456y48e8d78fn199675f2ae105c8@mail.gmail.com","threadId":"17454","inReplyTo":"adf1fd3d0901300318s5a0e4c94gab5f31342643ea52@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2009-01-30T12:56:20Z","receivedAt":"2009-01-30T12:56:20Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"Santi,\n\nThanks for you reply.\n\n> I think your definition is not well defined. A, B and C are just\n> branches of you project, technically they are equivalent. Maybe you\n\nRight. Yet I want to know from which branch a branch as been started.\n\nYou need this to get the proper merge-base for example:\n\n   $ git merge-base C A\n      1\n\n   $ git merge-base B C\n      2\n\n   $ git merge-base B A\n      1\n\nI always know on which topic branch I'm but, as shown above, depending on the\nparent branch passed to merge-base you do not get the same branch-point. This\nis fine.\n\nSo, when I'm in a topic branch I want to find the name of the parent\nbranch. The one given\nwhen creating the branch:\n\n   $ git branch B C\n\nA \"stupid\" solution whould be to iterate over all branches. Looking\nfor the merge-base and\nat the end output the branch having the youngest merge-base. I'm\nlooking for something\nmore efficient...\n\n> are thinking that the common commits of, say A and B, really belongs\n> to A, but this is not the case they belong to both branches. In git a\n> branch is really just a pointer to a commit and by extension the\n> history, it is not a series of commits.\n>\n> Just a counterexample, just rearranging you graph:\n>\n>                        o---B\n>                        /\n>                   o---2---o---o---o---C\n>                  /\n>          ---o---1---o---o---o---A\n>\n> From you description: For B I would get C and for C I would get A.\n\nDon't see this as a counter-example as it is exactly my example.\n\nDid I missed something?\n\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"102584","messageId":"adf1fd3d0901300516y3d1bf58dmda9c5172586d828@mail.gmail.com","threadId":"17454","inReplyTo":"a2633edd0901300456y48e8d78fn199675f2ae105c8@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-01-30T13:16:50Z","receivedAt":"2009-01-30T13:16:50Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/1/30 Pascal Obry <pascal@obry.net>:\n> Santi,\n>\n> Thanks for you reply.\n>\n>> I think your definition is not well defined. A, B and C are just\n>> branches of you project, technically they are equivalent. Maybe you\n>\n> Right. Yet I want to know from which branch a branch as been started.\n\nYou can set it when you create the branch:\n\ngit branch --track newbranch startpointbranch\n\n(maybe --track is the default these days for remote branches)\n\nAnd then the config keys:\n\nbranch.newbranch.remote\nbranch.newbranch.merge\n\nwill tell you from which branch a branch was started. And it is used\nin \"git pull\" to merge from the tracking branch.\n\n> You need this to get the proper merge-base for example:\n>\n>   $ git merge-base C A\n>      1\n>\n>   $ git merge-base B C\n>      2\n>\n>   $ git merge-base B A\n>      1\n\n1 and 2 are defined in the graph below...\n\n> I always know on which topic branch I'm but, as shown above, depending on the\n> parent branch passed to merge-base you do not get the same branch-point. This\n> is fine.\n>\n> So, when I'm in a topic branch I want to find the name of the parent\n> branch. The one given\n> when creating the branch:\n>\n>   $ git branch B C\n\nSee above.\n\n>\n> A \"stupid\" solution whould be to iterate over all branches. Looking\n> for the merge-base and\n> at the end output the branch having the youngest merge-base. I'm\n> looking for something\n> more efficient...\n>\n\nMaybe if you explain why you want it (a use case) instead of just this\nspecific problem...\n\n>> are thinking that the common commits of, say A and B, really belongs\n>> to A, but this is not the case they belong to both branches. In git a\n>> branch is really just a pointer to a commit and by extension the\n>> history, it is not a series of commits.\n>>\n>> Just a counterexample, just rearranging you graph:\n>>\n>>                        o---B\n>>                        /\n>>                   o---2---o---o---o---C\n>>                  /\n>>          ---o---1---o---o---o---A\n>>\n>> From you description: For B I would get C and for C I would get A.\n\nPlease, if you quote text do not edit it (the 1 and the 2 in this case).\n\n> Don't see this as a counter-example as it is exactly my example.\n>\n> Did I missed something?\n\nYes. Compare your sentence and mine:\n\nFor B I want to get A and for C I want to get B.\nFor B I would get C and for C I would get A.\n\nSo for B you get A while I get C, and the equivalent for C.\n\nSanti\n"},{"id":"102591","messageId":"a2633edd0901300535mf2d9ceemd9e9009e0aa18b40@mail.gmail.com","threadId":"17454","inReplyTo":"adf1fd3d0901300516y3d1bf58dmda9c5172586d828@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2009-01-30T13:35:39Z","receivedAt":"2009-01-30T13:35:39Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"Santi,\n\n> Maybe if you explain why you want it (a use case) instead of just this\n> specific problem...\n\nTo know the proper merge base to display all commits done on a specific\ntopic branch.\n\n>>> Just a counterexample, just rearranging you graph:\n>>>\n>>>                        o---B\n>>>                        /\n>>>                   o---2---o---o---o---C\n>>>                  /\n>>>          ---o---1---o---o---o---A\n>>>\n>>> From you description: For B I would get C and for C I would get A.\n>\n> Please, if you quote text do not edit it (the 1 and the 2 in this case).\n\nWell I've just added 1 and 2, nothing changed in the semantic!\n\n> Yes. Compare your sentence and mine:\n>\n> For B I want to get A and for C I want to get B.\n> For B I would get C and for C I would get A.\n>\n> So for B you get A while I get C, and the equivalent for C.\n\nOk, that's expected since you have renamed B to C and C to B.\n\nMy tree was:\n\n\n                        o---o---o---C\n                        /\n                   o---o---o---B\n                  /\n          ---o---o---o---o---o---A\n\nYour's was:\n\n                       o---B\n                       /\n                  o---o---o---o---o---C\n                 /\n         ---o---o---o---o---o---A\n\nSo when I said:\n\n    For B I want to get A and for C I want to get B.\n\nIt is equivalent to your (just rename B and C).:\n\n   For B I would get C and for C I would get A.\n\nFrankly I do not see your point... That's maybe the cause of the\nproblem I'm having....\n\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"102589","messageId":"4983023D.40907@drmicha.warpmail.net","threadId":"17454","inReplyTo":"a2633edd0901300456y48e8d78fn199675f2ae105c8@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-01-30T13:35:57Z","receivedAt":"2009-01-30T13:35:57Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Pascal Obry venit, vidit, dixit 30.01.2009 13:56:\n> Santi,\n> \n> Thanks for you reply.\n> \n>> I think your definition is not well defined. A, B and C are just\n>> branches of you project, technically they are equivalent. Maybe you\n> \n> Right. Yet I want to know from which branch a branch as been started.\n> \n> You need this to get the proper merge-base for example:\n> \n>    $ git merge-base C A\n>       1\n> \n>    $ git merge-base B C\n>       2\n> \n>    $ git merge-base B A\n>       1\n> \n> I always know on which topic branch I'm but, as shown above, depending on the\n> parent branch passed to merge-base you do not get the same branch-point. This\n> is fine.\n> \n> So, when I'm in a topic branch I want to find the name of the parent\n> branch. The one given\n> when creating the branch:\n> \n>    $ git branch B C\n> \n> A \"stupid\" solution whould be to iterate over all branches. Looking\n> for the merge-base and\n> at the end output the branch having the youngest merge-base. I'm\n> looking for something\n> more efficient...\n> \n>> are thinking that the common commits of, say A and B, really belongs\n>> to A, but this is not the case they belong to both branches. In git a\n>> branch is really just a pointer to a commit and by extension the\n>> history, it is not a series of commits.\n>>\n>> Just a counterexample, just rearranging you graph:\n>>\n>>                        o---B\n>>                        /\n>>                   o---2---o---o---o---C\n>>                  /\n>>          ---o---1---o---o---o---A\n>>\n>> From you description: For B I would get C and for C I would get A.\n> \n> Don't see this as a counter-example as it is exactly my example.\n> \n> Did I missed something?\n\nI think you still haven't *defined* what you mean by \"parent branch\".\nYour example alone doesn't define it, and whenever you have merge\ncommits things are not clear:\n\n     o---o---o---A\n    /     \\\n---o       o---o---C\n    \\     /\n     o---o---o---B\n\nNow, which one is the \"parent branch\" of C? A+B? Similarly:\n\n     o---A\n    /\n---o---C\n    \\\n     o---B\n\nHere it's clear which commit you want, but which branch does it belong\nto? A or B?\n\nI really think this is impossible to define unambiguously in git, due to\nthe nature of git branches, being movable tags, much different from say\nhg's hardwired branches (embedded in the commit object).\n\nWhat you see in gitk is which branch contains a certain commit (\"git\nbranch --contains\").\n\nWhat you want may be the branch which differs from C by the least number\nof commits.\n\nCheers,\nMichael\n"},{"id":"102593","messageId":"adf1fd3d0901300557t19ca4bccn7fe24013a05d2d57@mail.gmail.com","threadId":"17454","inReplyTo":"a2633edd0901300535mf2d9ceemd9e9009e0aa18b40@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-01-30T13:57:05Z","receivedAt":"2009-01-30T13:57:05Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/1/30 Pascal Obry <pascal@obry.net>:\n> Santi,\n>\n>> Maybe if you explain why you want it (a use case) instead of just this\n>> specific problem...\n>\n> To know the proper merge base to display all commits done on a specific\n> topic branch.\n>\n\ngitk topicbranch ^trackingbranch\n\nBut I agree that a way to refer to the tracking branch would be great, as:\n\nbranch^{origin}\n\nso you can say, for example:\n\ngitk topicbranch ^topicbranch^{origin}\n\n>>>> Just a counterexample, just rearranging you graph:\n>>>>\n>>>>                        o---B\n>>>>                        /\n>>>>                   o---2---o---o---o---C\n>>>>                  /\n>>>>          ---o---1---o---o---o---A\n>>>>\n>>>> From you description: For B I would get C and for C I would get A.\n>>\n>> Please, if you quote text do not edit it (the 1 and the 2 in this case).\n>\n> Well I've just added 1 and 2, nothing changed in the semantic!\n>\n>> Yes. Compare your sentence and mine:\n>>\n>> For B I want to get A and for C I want to get B.\n>> For B I would get C and for C I would get A.\n>>\n>> So for B you get A while I get C, and the equivalent for C.\n>\n> Ok, that's expected since you have renamed B to C and C to B.\n\nI did not rename B to C and C to B, I just draw them differently.\n\nLet's put name to the commits:\n\nYour tree:\n\n\n                        i---j---k---C\n                        /\n                   f---g---h---B\n                  /\n          ---a---b---c---d---e---A\n\nMy tree:\n\n                       h---B\n                       /\n                  f---g---i---j---k---C\n                 /\n         ---a---b---c---d---e---A\n\nSo the commits in all the branches are equal, the only change is that\nI painted B above C.\n\n> So when I said:\n>\n>    For B I want to get A and for C I want to get B.\n>\n> It is equivalent to your (just rename B and C).:\n>\n>   For B I would get C and for C I would get A.\n>\n> Frankly I do not see your point... That's maybe the cause of the\n> problem I'm having....\n\nAt least part of. You have to understand the branch model:\n\ngit model:\n  * a branch is just a pointer to a commit\n  * you cannot say \"this commit was done in that branch\"\n  * what you can say is \"this commit is contained in that branch\"\n\nin contrast to other models:\n  * where a commit really belongs to a branch (it is specified at\ncommit time somehow)\n  * you can say \"this commit was done in that branch\"\n\nHTH,\nSanti\n"},{"id":"102597","messageId":"a2633edd0901300606ub4c507bocccb6747b436f01f@mail.gmail.com","threadId":"17454","inReplyTo":"adf1fd3d0901300557t19ca4bccn7fe24013a05d2d57@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2009-01-30T14:06:12Z","receivedAt":"2009-01-30T14:06:12Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"Santi,\n\nThanks for your patience!\n\n> gitk topicbranch ^trackingbranch\n>\n> But I agree that a way to refer to the tracking branch would be great, as:\n>\n> branch^{origin}\n>\n> so you can say, for example:\n>\n> gitk topicbranch ^topicbranch^{origin}\n\nThat's exactly what I'm looking for!\n\n> At least part of. You have to understand the branch model:\n>\n> git model:\n>  * a branch is just a pointer to a commit\n>  * you cannot say \"this commit was done in that branch\"\n>  * what you can say is \"this commit is contained in that branch\"\n\nThe second point wasn't clear to me.\n\nI had 2 out of 3 OK :)\n\nThanks.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"102602","messageId":"200901301526.24566.thomas.koch@ymc.ch","threadId":"17454","inReplyTo":"a2633edd0901300256k2ad7530elcaca5cdc30c17534@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Thomas Koch","fromEmail":"thomas.koch@ymc.ch","sentAt":"2009-01-30T14:26:24Z","receivedAt":"2009-01-30T14:26:24Z","isPatch":false,"sender":{"key":"thomas.koch@ymc.ch","avatar":null},"body":"Am Friday 30 January 2009 11:56:12 schrieb Pascal Obry:\n> I want to find the name of the parent branch in a script. What is the best\n> way?\n>\n>                          o---o---o---C\n>                          /\n>                     o---o---o---B\n>                    /\n>            ---o---o---o---o---o---A\n>\n> For B I want to get A and for C I want to get B.\n>\n> All this can be found in gitk, but from a script I did not found a\n> good solution.\n>\n> Any idea?\n>\n> Thanks.\n> Pascal.\n\nIsn't your problem solved by topgit?\n\n-- \nThomas Koch, YMC AG, http://www.ymc.ch\nPhone: +41 (0)71 / 508 24 86\n"},{"id":"102601","messageId":"adf1fd3d0901300646h39e27f50pdb6510083284cf8a@mail.gmail.com","threadId":"17454","inReplyTo":"a2633edd0901300606ub4c507bocccb6747b436f01f@mail.gmail.com","subject":"Re: Finding the name of the parent branch?","fromName":"Santi Béjar","fromEmail":"santi@agolina.net","sentAt":"2009-01-30T14:46:27Z","receivedAt":"2009-01-30T14:46:27Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2009/1/30 Pascal Obry <pascal@obry.net>:\n>> At least part of. You have to understand the branch model:\n>>\n>> git model:\n>>  * a branch is just a pointer to a commit\n>>  * you cannot say \"this commit was done in that branch\"\n>>  * what you can say is \"this commit is contained in that branch\"\n>\n> The second point wasn't clear to me.\n\nA practical example:\n\n$ git clone path/to/project.git\n$ cd project\n$ git checkout -b bugfix-1234 origin/master\n$ # hack, hack, hack\n$ git commit -a -m \"Fix for the Bug #1234\"\n$ git push origin HEAD:master\n\nSo, you've done a commit in a local branch named bugfix-1234 and once\nyou push it to the master branch in origin there is nothing to tell\nyou so. A commit is defined with the current state, the old commit(s)\nand some metadata (author and committer) but nothing about which\nbranch it was made, and as a branch is a pointer to a commit there is\nnothing more.\n\nSanti\n"},{"id":"102607","messageId":"498323AF.5060307@obry.net","threadId":"17454","inReplyTo":"200901301526.24566.thomas.koch@ymc.ch","subject":"Re: Finding the name of the parent branch?","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2009-01-30T15:58:39Z","receivedAt":"2009-01-30T15:58:39Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"Thomas Koch a écrit :\n> Isn't your problem solved by topgit?\n\nDon't know! I have never used topgit. Why do you think so?\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"}]}