* Finding the name of the parent branch? @ 2009-01-30 10:56 Pascal Obry 2009-01-30 11:18 ` Santi Béjar 2009-01-30 14:26 ` Thomas Koch 0 siblings, 2 replies; 11+ messages in thread From: Pascal Obry @ 2009-01-30 10:56 UTC (permalink / raw) To: Git Mailing List I want to find the name of the parent branch in a script. What is the best way? o---o---o---C / o---o---o---B / ---o---o---o---o---o---A For B I want to get A and for C I want to get B. All this can be found in gitk, but from a script I did not found a good solution. Any idea? Thanks. Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 10:56 Finding the name of the parent branch? Pascal Obry @ 2009-01-30 11:18 ` Santi Béjar 2009-01-30 12:56 ` Pascal Obry 2009-01-30 14:26 ` Thomas Koch 1 sibling, 1 reply; 11+ messages in thread From: Santi Béjar @ 2009-01-30 11:18 UTC (permalink / raw) To: Pascal Obry; +Cc: Git Mailing List 2009/1/30 Pascal Obry <pascal@obry.net>: > I want to find the name of the parent branch in a script. What is the best way? > > o---o---o---C > / > o---o---o---B > / > ---o---o---o---o---o---A > > For B I want to get A and for C I want to get B. I think your definition is not well defined. A, B and C are just branches of you project, technically they are equivalent. Maybe you are thinking that the common commits of, say A and B, really belongs to A, but this is not the case they belong to both branches. In git a branch is really just a pointer to a commit and by extension the history, it is not a series of commits. Just a counterexample, just rearranging you graph: o---B / o---o---o---o---o---C / ---o---o---o---o---o---A >From you description: For B I would get C and for C I would get A. HTH, Santi ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 11:18 ` Santi Béjar @ 2009-01-30 12:56 ` Pascal Obry 2009-01-30 13:16 ` Santi Béjar 2009-01-30 13:35 ` Michael J Gruber 0 siblings, 2 replies; 11+ messages in thread From: Pascal Obry @ 2009-01-30 12:56 UTC (permalink / raw) To: Santi Béjar; +Cc: Git Mailing List Santi, Thanks for you reply. > I think your definition is not well defined. A, B and C are just > branches of you project, technically they are equivalent. Maybe you Right. Yet I want to know from which branch a branch as been started. You need this to get the proper merge-base for example: $ git merge-base C A 1 $ git merge-base B C 2 $ git merge-base B A 1 I always know on which topic branch I'm but, as shown above, depending on the parent branch passed to merge-base you do not get the same branch-point. This is fine. So, when I'm in a topic branch I want to find the name of the parent branch. The one given when creating the branch: $ git branch B C A "stupid" solution whould be to iterate over all branches. Looking for the merge-base and at the end output the branch having the youngest merge-base. I'm looking for something more efficient... > are thinking that the common commits of, say A and B, really belongs > to A, but this is not the case they belong to both branches. In git a > branch is really just a pointer to a commit and by extension the > history, it is not a series of commits. > > Just a counterexample, just rearranging you graph: > > o---B > / > o---2---o---o---o---C > / > ---o---1---o---o---o---A > > From you description: For B I would get C and for C I would get A. Don't see this as a counter-example as it is exactly my example. Did I missed something? Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 12:56 ` Pascal Obry @ 2009-01-30 13:16 ` Santi Béjar 2009-01-30 13:35 ` Pascal Obry 2009-01-30 13:35 ` Michael J Gruber 1 sibling, 1 reply; 11+ messages in thread From: Santi Béjar @ 2009-01-30 13:16 UTC (permalink / raw) To: Pascal Obry; +Cc: Git Mailing List 2009/1/30 Pascal Obry <pascal@obry.net>: > Santi, > > Thanks for you reply. > >> I think your definition is not well defined. A, B and C are just >> branches of you project, technically they are equivalent. Maybe you > > Right. Yet I want to know from which branch a branch as been started. You can set it when you create the branch: git branch --track newbranch startpointbranch (maybe --track is the default these days for remote branches) And then the config keys: branch.newbranch.remote branch.newbranch.merge will tell you from which branch a branch was started. And it is used in "git pull" to merge from the tracking branch. > You need this to get the proper merge-base for example: > > $ git merge-base C A > 1 > > $ git merge-base B C > 2 > > $ git merge-base B A > 1 1 and 2 are defined in the graph below... > I always know on which topic branch I'm but, as shown above, depending on the > parent branch passed to merge-base you do not get the same branch-point. This > is fine. > > So, when I'm in a topic branch I want to find the name of the parent > branch. The one given > when creating the branch: > > $ git branch B C See above. > > A "stupid" solution whould be to iterate over all branches. Looking > for the merge-base and > at the end output the branch having the youngest merge-base. I'm > looking for something > more efficient... > Maybe if you explain why you want it (a use case) instead of just this specific problem... >> are thinking that the common commits of, say A and B, really belongs >> to A, but this is not the case they belong to both branches. In git a >> branch is really just a pointer to a commit and by extension the >> history, it is not a series of commits. >> >> Just a counterexample, just rearranging you graph: >> >> o---B >> / >> o---2---o---o---o---C >> / >> ---o---1---o---o---o---A >> >> From you description: For B I would get C and for C I would get A. Please, if you quote text do not edit it (the 1 and the 2 in this case). > Don't see this as a counter-example as it is exactly my example. > > Did I missed something? Yes. Compare your sentence and mine: For B I want to get A and for C I want to get B. For B I would get C and for C I would get A. So for B you get A while I get C, and the equivalent for C. Santi ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 13:16 ` Santi Béjar @ 2009-01-30 13:35 ` Pascal Obry 2009-01-30 13:57 ` Santi Béjar 0 siblings, 1 reply; 11+ messages in thread From: Pascal Obry @ 2009-01-30 13:35 UTC (permalink / raw) To: Santi Béjar; +Cc: Git Mailing List Santi, > Maybe if you explain why you want it (a use case) instead of just this > specific problem... To know the proper merge base to display all commits done on a specific topic branch. >>> Just a counterexample, just rearranging you graph: >>> >>> o---B >>> / >>> o---2---o---o---o---C >>> / >>> ---o---1---o---o---o---A >>> >>> From you description: For B I would get C and for C I would get A. > > Please, if you quote text do not edit it (the 1 and the 2 in this case). Well I've just added 1 and 2, nothing changed in the semantic! > Yes. Compare your sentence and mine: > > For B I want to get A and for C I want to get B. > For B I would get C and for C I would get A. > > So for B you get A while I get C, and the equivalent for C. Ok, that's expected since you have renamed B to C and C to B. My tree was: o---o---o---C / o---o---o---B / ---o---o---o---o---o---A Your's was: o---B / o---o---o---o---o---C / ---o---o---o---o---o---A So when I said: For B I want to get A and for C I want to get B. It is equivalent to your (just rename B and C).: For B I would get C and for C I would get A. Frankly I do not see your point... That's maybe the cause of the problem I'm having.... Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 13:35 ` Pascal Obry @ 2009-01-30 13:57 ` Santi Béjar 2009-01-30 14:06 ` Pascal Obry 0 siblings, 1 reply; 11+ messages in thread From: Santi Béjar @ 2009-01-30 13:57 UTC (permalink / raw) To: Pascal Obry; +Cc: Git Mailing List 2009/1/30 Pascal Obry <pascal@obry.net>: > Santi, > >> Maybe if you explain why you want it (a use case) instead of just this >> specific problem... > > To know the proper merge base to display all commits done on a specific > topic branch. > gitk topicbranch ^trackingbranch But I agree that a way to refer to the tracking branch would be great, as: branch^{origin} so you can say, for example: gitk topicbranch ^topicbranch^{origin} >>>> Just a counterexample, just rearranging you graph: >>>> >>>> o---B >>>> / >>>> o---2---o---o---o---C >>>> / >>>> ---o---1---o---o---o---A >>>> >>>> From you description: For B I would get C and for C I would get A. >> >> Please, if you quote text do not edit it (the 1 and the 2 in this case). > > Well I've just added 1 and 2, nothing changed in the semantic! > >> Yes. Compare your sentence and mine: >> >> For B I want to get A and for C I want to get B. >> For B I would get C and for C I would get A. >> >> So for B you get A while I get C, and the equivalent for C. > > Ok, that's expected since you have renamed B to C and C to B. I did not rename B to C and C to B, I just draw them differently. Let's put name to the commits: Your tree: i---j---k---C / f---g---h---B / ---a---b---c---d---e---A My tree: h---B / f---g---i---j---k---C / ---a---b---c---d---e---A So the commits in all the branches are equal, the only change is that I painted B above C. > So when I said: > > For B I want to get A and for C I want to get B. > > It is equivalent to your (just rename B and C).: > > For B I would get C and for C I would get A. > > Frankly I do not see your point... That's maybe the cause of the > problem I'm having.... At least part of. You have to understand the branch model: git model: * a branch is just a pointer to a commit * you cannot say "this commit was done in that branch" * what you can say is "this commit is contained in that branch" in contrast to other models: * where a commit really belongs to a branch (it is specified at commit time somehow) * you can say "this commit was done in that branch" HTH, Santi ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 13:57 ` Santi Béjar @ 2009-01-30 14:06 ` Pascal Obry 2009-01-30 14:46 ` Santi Béjar 0 siblings, 1 reply; 11+ messages in thread From: Pascal Obry @ 2009-01-30 14:06 UTC (permalink / raw) To: Santi Béjar; +Cc: Git Mailing List Santi, Thanks for your patience! > gitk topicbranch ^trackingbranch > > But I agree that a way to refer to the tracking branch would be great, as: > > branch^{origin} > > so you can say, for example: > > gitk topicbranch ^topicbranch^{origin} That's exactly what I'm looking for! > At least part of. You have to understand the branch model: > > git model: > * a branch is just a pointer to a commit > * you cannot say "this commit was done in that branch" > * what you can say is "this commit is contained in that branch" The second point wasn't clear to me. I had 2 out of 3 OK :) Thanks. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 14:06 ` Pascal Obry @ 2009-01-30 14:46 ` Santi Béjar 0 siblings, 0 replies; 11+ messages in thread From: Santi Béjar @ 2009-01-30 14:46 UTC (permalink / raw) To: Pascal Obry; +Cc: Git Mailing List 2009/1/30 Pascal Obry <pascal@obry.net>: >> At least part of. You have to understand the branch model: >> >> git model: >> * a branch is just a pointer to a commit >> * you cannot say "this commit was done in that branch" >> * what you can say is "this commit is contained in that branch" > > The second point wasn't clear to me. A practical example: $ git clone path/to/project.git $ cd project $ git checkout -b bugfix-1234 origin/master $ # hack, hack, hack $ git commit -a -m "Fix for the Bug #1234" $ git push origin HEAD:master So, you've done a commit in a local branch named bugfix-1234 and once you push it to the master branch in origin there is nothing to tell you so. A commit is defined with the current state, the old commit(s) and some metadata (author and committer) but nothing about which branch it was made, and as a branch is a pointer to a commit there is nothing more. Santi ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 12:56 ` Pascal Obry 2009-01-30 13:16 ` Santi Béjar @ 2009-01-30 13:35 ` Michael J Gruber 1 sibling, 0 replies; 11+ messages in thread From: Michael J Gruber @ 2009-01-30 13:35 UTC (permalink / raw) To: Pascal Obry; +Cc: Santi Béjar, Git Mailing List Pascal Obry venit, vidit, dixit 30.01.2009 13:56: > Santi, > > Thanks for you reply. > >> I think your definition is not well defined. A, B and C are just >> branches of you project, technically they are equivalent. Maybe you > > Right. Yet I want to know from which branch a branch as been started. > > You need this to get the proper merge-base for example: > > $ git merge-base C A > 1 > > $ git merge-base B C > 2 > > $ git merge-base B A > 1 > > I always know on which topic branch I'm but, as shown above, depending on the > parent branch passed to merge-base you do not get the same branch-point. This > is fine. > > So, when I'm in a topic branch I want to find the name of the parent > branch. The one given > when creating the branch: > > $ git branch B C > > A "stupid" solution whould be to iterate over all branches. Looking > for the merge-base and > at the end output the branch having the youngest merge-base. I'm > looking for something > more efficient... > >> are thinking that the common commits of, say A and B, really belongs >> to A, but this is not the case they belong to both branches. In git a >> branch is really just a pointer to a commit and by extension the >> history, it is not a series of commits. >> >> Just a counterexample, just rearranging you graph: >> >> o---B >> / >> o---2---o---o---o---C >> / >> ---o---1---o---o---o---A >> >> From you description: For B I would get C and for C I would get A. > > Don't see this as a counter-example as it is exactly my example. > > Did I missed something? I think you still haven't *defined* what you mean by "parent branch". Your example alone doesn't define it, and whenever you have merge commits things are not clear: o---o---o---A / \ ---o o---o---C \ / o---o---o---B Now, which one is the "parent branch" of C? A+B? Similarly: o---A / ---o---C \ o---B Here it's clear which commit you want, but which branch does it belong to? A or B? I really think this is impossible to define unambiguously in git, due to the nature of git branches, being movable tags, much different from say hg's hardwired branches (embedded in the commit object). What you see in gitk is which branch contains a certain commit ("git branch --contains"). What you want may be the branch which differs from C by the least number of commits. Cheers, Michael ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 10:56 Finding the name of the parent branch? Pascal Obry 2009-01-30 11:18 ` Santi Béjar @ 2009-01-30 14:26 ` Thomas Koch 2009-01-30 15:58 ` Pascal Obry 1 sibling, 1 reply; 11+ messages in thread From: Thomas Koch @ 2009-01-30 14:26 UTC (permalink / raw) To: Pascal Obry; +Cc: Git Mailing List Am Friday 30 January 2009 11:56:12 schrieb Pascal Obry: > I want to find the name of the parent branch in a script. What is the best > way? > > o---o---o---C > / > o---o---o---B > / > ---o---o---o---o---o---A > > For B I want to get A and for C I want to get B. > > All this can be found in gitk, but from a script I did not found a > good solution. > > Any idea? > > Thanks. > Pascal. Isn't your problem solved by topgit? -- Thomas Koch, YMC AG, http://www.ymc.ch Phone: +41 (0)71 / 508 24 86 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Finding the name of the parent branch? 2009-01-30 14:26 ` Thomas Koch @ 2009-01-30 15:58 ` Pascal Obry 0 siblings, 0 replies; 11+ messages in thread From: Pascal Obry @ 2009-01-30 15:58 UTC (permalink / raw) To: thomas.koch; +Cc: Git Mailing List Thomas Koch a écrit : > Isn't your problem solved by topgit? Don't know! I have never used topgit. Why do you think so? -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2009-01-30 15:59 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-01-30 10:56 Finding the name of the parent branch? Pascal Obry 2009-01-30 11:18 ` Santi Béjar 2009-01-30 12:56 ` Pascal Obry 2009-01-30 13:16 ` Santi Béjar 2009-01-30 13:35 ` Pascal Obry 2009-01-30 13:57 ` Santi Béjar 2009-01-30 14:06 ` Pascal Obry 2009-01-30 14:46 ` Santi Béjar 2009-01-30 13:35 ` Michael J Gruber 2009-01-30 14:26 ` Thomas Koch 2009-01-30 15:58 ` Pascal Obry
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).