git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Finding a branch point in git

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 31, 2012, 15:27 UTC
Message-ID
<CAMP44s1Q26B9hCdubfDiP2_YUUWGOtyyA=gSwqpGOE4FfZrN8A@mail.gmail.com>
In-Reply-To
<20120530215415.GB3237@sigill.intra.peff.net>
On Wed, May 30, 2012 at 11:54 PM, Jeff King <peff@peff.net> wrote:
Show 31 quoted lines
> On Wed, May 30, 2012 at 07:07:39PM +0200, Felipe Contreras wrote:
>
>> On Mon, May 28, 2012 at 9:06 PM, Jeff King <peff@peff.net> wrote:
>> > On Mon, May 28, 2012 at 02:36:04PM +0200, Felipe Contreras wrote:
>> >
>> >> > What about a history with multiple branches?
>> >> >
>> >> > --X--A--B--C--D----E  (master)
>> >> >      \           /
>> >> >       G--H--I---J   (branch X)
>> >> >           \    /
>> >> >            K--L    (branch Y)
>> >> [...]
>> >>
>> >> Yes, but then you would need to specify a second branch. I would avoid
>> >> that if possible.
>> >
>> > I agree that is less nice. But I don't think the operation is
>> > well-defined with a single branch. If you ask for "when did branch X
>> > split", then in the above graph it is unclear if you meant "split from
>> > master", or "split from Y".
>>
>> If you look from the context that I explained in the first mail; it
>> would be from *any* branch; IOW; find the first commit from branch X
>> (G), and then find the parent. That would be the first commit where
>> branch X started.
>
> I'm not sure that's possible, though, in the face of criss-cross merges.
> How do we distinguish the history above from one in which branch Y was
> forked from master at G, and then branch X was forked from branch Y at
> H?

That is true, but we could use the algorithm used by name-rev: G would have a distance 3 from branch X, and distance 2 from Y, so it would be considered part of branch Y.

Sure, it's not possible to know _for sure_, but this is a bit like renames; we don't really know if a file was renamed or not, but we can make a good guess.

Show 13 quoted lines
>> I think it would be easy to support this case if somehow there was a
>> way to find all the commits that comprise a branch;
>>
>>  % git log branch ^<any-other-branch>
>>
>> I could swear I saw such an option, but I've been looking for days and
>> I can't find it.
>
> I don't think there is such an option. You have to do something like:
>
>  {
>    echo "--not"
>    git for-each-ref --format='%(refname)' | grep -v "^$branch\$"

Rather: git for-each-ref --format='%(refname:short)' refs/heads | grep -v "^$branch\$"

>  } |
>  git rev-list --stdin $branch
Cheers.
-- 
Felipe Contreras
Previous: Jeff KingNext: Felipe Contreras
Message 7 of 13 in “Finding a branch point in git”
  1. Felipe ContrerasMay 27, 2012
  2. Jeff KingMay 28, 2012
  3. Felipe ContrerasMay 28, 2012
  4. Jeff KingMay 28, 2012
  5. Felipe ContrerasMay 30, 2012
  6. Jeff KingMay 30, 2012
  7. Felipe ContrerasMay 31, 2012
  8. Felipe ContrerasMay 31, 2012
  9. PJ WeisbergMay 31, 2012
  10. Felipe ContrerasJun 1, 2012
  11. Martin LanghoffMay 31, 2012
  12. Felipe ContrerasMay 30, 2012
  13. Jeff KingMay 30, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.