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

Re: Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?

From
Elijah Newren <newren@gmail.com>
Date
Jul 21, 2022, 19:34 UTC
Message-ID
<CABPp-BEqWX3Nr2HDxwS9d-_QjcKb_jS=fSjsP_Pbutw7-P5gbg@mail.gmail.com>
In-Reply-To
<xmqqy1wmlbnn.fsf@gitster.g>
On Thu, Jul 21, 2022 at 8:37 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
>
> Elijah Newren <newren@gmail.com> writes:
>
> > A simple question that I'm spinning out of [1]: How can I get `git
> > log` to show the commits in the ancestry path from seen, back to *and
> > including* a given topic (but not commits from unrelated topics)?
>
> Drawing of a sample history, please.
>
> I feel stupid asking this, but I do not think I even understand what
> the question is X-<.
>
> Commits that are ancestors of 'seen' and are descendants of the tip
> of the topic?
What you said *plus* commits from the topic itself.  From this graph:
    A---B---C---J---K <-- main
            |\       \
            | \       N---------------O---P---Q <-- seen
            |  \     /               /
            |   L---M  <-- topic    /
             \                     /
              D---E---F---G---H---I  <-- other_topic
I want the commits L-Q.  If I run
   git log --ancestry-path topic..seen
I only get N-Q, missing L & M.  If I run
   git log --ancestry-path main..seen
then I get D-Q, providing me with D-I and J-K that I don't want.
The closest I seem to be able to get is
   git log --ancestry-path topic~${commits_in_topic_minus_one}..seen

which includes all commits I want except the first commit of the topic branch.

An example, from git.git; 5b893f7d81 is a topic (ab/submodule-cleanup) with 12 commits, and ac0248bfba is some older version of 'next' . I want all 12 commits in that topic plus all commits that are both descendants of that tip and ancestors of that old version of 'next', which adds up to 36 commits. (Note that this includes the 12 commits in ab/submodule clean, 9 commits from gc/submodule-use-super-prefix since that happens to be a descendant of ab/submodule-cleanup, and about 15 merge commits from merging other topics into next, but does not include those other 15 topics.) If I run (notice the "11" instead of "12"):

   git log --oneline --ancestry-path 5b893f7d81~11..ac0248bfba | wc -l

it reports 35 commits -- it's just missing the first commit from the topic. If I change "11" to "12" to try to get that first commit too:

   git log --oneline --ancestry-path 5b893f7d81~11..ac0248bfba | wc -l
then it reports 228 commits, 192 of which I don't want.
Previous: Derrick StoleeNext: Derrick Stolee
Message 4 of 6 in “Question: How to find the commits in the ancestry path of seen down to _and_ including a given topic?”
  1. Elijah NewrenJul 21, 2022
  2. Junio C HamanoJul 21, 2022
  3. Derrick StoleeJul 21, 2022
  4. Elijah NewrenJul 21, 2022
  5. Derrick StoleeJul 22, 2022
  6. Elijah NewrenJul 22, 2022

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.