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

Re: Find out on which branch a commit was originally made

From
ASArtur Skawina <art.08.09@gmail.com>
Date
Sep 19, 2010, 14:03 UTC
Message-ID
<4C96183E.7020208@gmail.com>
In-Reply-To
<1jp2d5s.1q4xl2w1f5ufljM%lists@haller-berlin.de>
On 09/19/10 11:45, Stefan Haller wrote:
Show 17 quoted lines
> Artur Skawina <art.08.09@gmail.com> wrote:
> 
>> On 09/18/10 17:26, Stefan Haller wrote:
>>> Ævar Arnfjör? Bjarmason <avarab@gmail.com> wrote:
>>>>                      A---B---C topic
>>>>                     /         \
>>>>                D---E---F---G---H master
>>
>>> The question is the same though: if I hit commit B while blaming, how do
>>> I know what topic it was a part of?  For that, I need to find commit H
>>> which will tell me, right?  How do I do that?
>>
>> git rev-list --ancestry-path --merges --reverse B..master --format=oneline
> 
> Thanks, this is helpful.  (However, my co-workers will probably laugh at
> me if I suggest they remember a command such as this for what they think
> should be a very simple operation.)
An alias such as "git show-merges-since B" might help.
Show 9 quoted lines
> There's a problem though for commits that are far back in history:
> 
>                A---B---C topic
>               /         \
>          D---E---F---G---H---I---J---K---L---M---N master
>                                   \         /
>                                    O---P---Q another-topic
> 
> Your command also shows M, which is not interesting at all in this

But you're only interested in the name of the original topic branch, right? Then the first merge will tell you that; I omitted "| head -1" from the cmdline above, just in case the history isn't as simple as in this graph.

> context.  Ideally it should stop at the first command that's common to
> topic and master.  Is there an easy way to achieve that?

Well, as you've explicitly deleted the 'topic' ref, how is git supposed to find it?

The above "git rev-list" will give you either the merge w/ the info you are looking for, or a list of merge commits that you'll have to filter (grep etc) to find the first one containing the answer.

Show 9 quoted lines
>> IOW if you know you could still need the old branch info, make an alias
>> that doesn't actually delete the branch after merging, but moves the ref
>> away, eg 'topic-name' -> "merged/topic-name" or just adds a
>> "merged/topic-name" tag. Then simply checking from which "merged/*"
>> branch/tag the offending commit is reachable would be enough.
> 
> Same problem here: this also shows all branches that were created and
> merged after the original topic was merged.  (In the example above, it
> will also list another-topic.)  This makes it pretty much impossible to

Yes. "git merge-base master another-topic" would return 'J' and if 'B' is still reachable from 'J' then 'another-topic' isn't the answer and you have to keep looking. So it's a bit more complicated.

artur
Previous: Clemens BuchacherNext: Stefan Haller
Message 9 of 33 in “Find out on which branch a commit was originally made”
  1. Stefan HallerSep 18, 2010
  2. Ævar Arnfjörð BjarmasonSep 18, 2010
  3. Ævar Arnfjörð BjarmasonSep 18, 2010
  4. Tor ArntsenSep 18, 2010
  5. Stefan HallerSep 18, 2010
  6. Artur SkawinaSep 18, 2010
  7. Stefan HallerSep 19, 2010
  8. Clemens BuchacherSep 19, 2010
  9. Artur SkawinaSep 19, 2010
  10. Stefan HallerSep 19, 2010
  11. Artur SkawinaSep 19, 2010
  12. Robin RosenbergSep 19, 2010
  13. Seth RobertsonSep 19, 2010
  14. Artur SkawinaSep 19, 2010
  15. Seth RobertsonSep 19, 2010
  16. Artur SkawinaSep 20, 2010
  17. Seth RobertsonSep 20, 2010
  18. Stefan HallerSep 20, 2010
  19. Artur SkawinaSep 20, 2010
  20. Artur SkawinaSep 20, 2010
  21. Seth RobertsonSep 21, 2010
  22. Artur SkawinaSep 21, 2010
  23. ANNOUNCE git-what-branch (was Re: Find out on which branch a commit was originally made)Seth Robertson, Sep 22, 2010
  24. Artur SkawinaSep 22, 2010
  25. Seth RobertsonSep 22, 2010
  26. Stephen BashSep 23, 2010
  27. Ævar Arnfjörð BjarmasonSep 23, 2010
  28. Artur SkawinaSep 23, 2010
  29. Artur SkawinaSep 24, 2010
  30. Seth RobertsonSep 24, 2010
  31. Seth RobertsonSep 23, 2010
  32. Stefan HallerSep 20, 2010
  33. Bryan DrewerySep 24, 2010

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.