# How to get next commit that just after a specified commit

6 messages from 2019-02-13 to 2019-02-18. Participants: wuzhouhui, Ævar Arnfjörð Bjarmason, Junio C Hamano, Philip Oakley, Derrick Stolee.
Thread: https://gitlist.dev/t/50489

## wuzhouhui, 2019-02-13 09:08

Subject: How to get next commit that just after a specified commit
Message-ID: <383c14cc.9289.168e61d39e8.Coremail.wuzhouhui14@mails.ucas.ac.cn>
URL: https://gitlist.dev/e/383c14cc.9289.168e61d39e8.Coremail.wuzhouhui14%40mails.ucas.ac.cn

```
Hi,

I have searched Internet for while but couldn't find the answer.

Suppose I have commit
  212146f0800e
then commit
  73a4c5218414
and finally commit
  aadaa8061189

So I get following after 'git log':
  aadaa8061189
  73a4c5218414
  212146f0800e

And now, my question is how to retrieve the next commit (i.e. 73a4c5218414)
that just after 212146f0800e?

Please CC me.

Thanks.
```

## Ævar Arnfjörð Bjarmason, 2019-02-13 09:49

Subject: Re: How to get next commit that just after a specified commit
Message-ID: <87mun0j9vv.fsf@evledraar.gmail.com>
URL: https://gitlist.dev/e/87mun0j9vv.fsf%40evledraar.gmail.com
In-Reply-To: <383c14cc.9289.168e61d39e8.Coremail.wuzhouhui14@mails.ucas.ac.cn>

```
(Replying to
https://public-inbox.org/git/383c14cc.9289.168e61d39e8.Coremail.wuzhouhui14@mails.ucas.ac.cn/
which curiously I can see there, but not in my inbox (or spam))

Git's data format doesn't make it easy to find "C" given "B" in a commit
chain like A->B->C (also there could be any number of "C"
successors). We need to walk the graph. This shows how to do it:

https://sqlite.org/whynotgit.html#git_makes_it_difficult_to_find_successors_descendents_of_a_check_in

```

## Junio C Hamano, 2019-02-13 21:12

Subject: Re: How to get next commit that just after a specified commit
Message-ID: <xmqqimxnbdfq.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqimxnbdfq.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <87mun0j9vv.fsf@evledraar.gmail.com>

```
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> (Replying to
> https://public-inbox.org/git/383c14cc.9289.168e61d39e8.Coremail.wuzhouhui14@mails.ucas.ac.cn/
> which curiously I can see there, but not in my inbox (or spam))
>
> Git's data format doesn't make it easy to find "C" given "B" in a commit
> chain like A->B->C (also there could be any number of "C"
> successors). We need to walk the graph. This shows how to do it:
>
> https://sqlite.org/whynotgit.html#git_makes_it_difficult_to_find_successors_descendents_of_a_check_in

Of course, the history is not necessarily linear.  Even though you
*MUST* know all your parents before having a commit (which means
that when you ask "what came before this commit", there is a
definitive answer that everybody in the world would agree on), you
by definition cannot know all the commits that are children of a
commit (simply because somebody else may be creating a new one), so
the question "what's the next commit" does not make any sense from
that point of view ;-)


```

## Ævar Arnfjörð Bjarmason, 2019-02-13 21:36

Subject: Re: How to get next commit that just after a specified commit
Message-ID: <87ef8bjrqv.fsf@evledraar.gmail.com>
URL: https://gitlist.dev/e/87ef8bjrqv.fsf%40evledraar.gmail.com
In-Reply-To: <xmqqimxnbdfq.fsf@gitster-ct.c.googlers.com>

```

On Wed, Feb 13 2019, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> (Replying to
>> https://public-inbox.org/git/383c14cc.9289.168e61d39e8.Coremail.wuzhouhui14@mails.ucas.ac.cn/
>> which curiously I can see there, but not in my inbox (or spam))
>>
>> Git's data format doesn't make it easy to find "C" given "B" in a commit
>> chain like A->B->C (also there could be any number of "C"
>> successors). We need to walk the graph. This shows how to do it:
>>
>> https://sqlite.org/whynotgit.html#git_makes_it_difficult_to_find_successors_descendents_of_a_check_in

I didn't mean to link to that fossil page to start some fossil v.s. git
argument. I just remembered having seen the one-liner there.

> Of course, the history is not necessarily linear.  Even though you
> *MUST* know all your parents before having a commit (which means
> that when you ask "what came before this commit", there is a
> definitive answer that everybody in the world would agree on), you
> by definition cannot know all the commits that are children of a
> commit (simply because somebody else may be creating a new one), so
> the question "what's the next commit" does not make any sense from
> that point of view ;-)

This is the case with fossil as well. You could create a new descendant
commit at any moment.

Their point in comparing it to git is that there's nothing intuitive in
the UI that exposes this information for the *current* graph, whereas in
fossil this is a built-in command:
https://fossil-scm.org/xfer/help/descendants

Perhaps this information is cheaper to extract these days with the
commit graph and we could expose it somehow?

```

## Philip Oakley, 2019-02-15 10:58

Subject: Re: How to get next commit that just after a specified commit
Message-ID: <fbf09f23-6f9c-2353-2416-8c2a12f9cf48@iee.org>
URL: https://gitlist.dev/e/fbf09f23-6f9c-2353-2416-8c2a12f9cf48%40iee.org
In-Reply-To: <xmqqimxnbdfq.fsf@gitster-ct.c.googlers.com>

```
On 13/02/2019 21:12, Junio C Hamano wrote:
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> (Replying to
>> https://public-inbox.org/git/383c14cc.9289.168e61d39e8.Coremail.wuzhouhui14@mails.ucas.ac.cn/
>> which curiously I can see there, but not in my inbox (or spam))
>>
>> Git's data format doesn't make it easy to find "C" given "B" in a commit
>> chain like A->B->C (also there could be any number of "C"
>> successors). We need to walk the graph. This shows how to do it:
>>
>> https://sqlite.org/whynotgit.html#git_makes_it_difficult_to_find_successors_descendents_of_a_check_in
> Of course, the history is not necessarily linear.  Even though you
> *MUST* know all your parents before having a commit (which means
> that when you ask "what came before this commit", there is a
> definitive answer that everybody in the world would agree on), you
> by definition cannot know all the commits that are children of a
> commit (simply because somebody else may be creating a new one), so
> the question "what's the next commit" does not make any sense from
> that point of view ;-)

It will also depend on which heads (branches) one wishes to trace back 
from, or even know about. I'd expect that the default would just be the 
current branch (head) which would definitely limit the potential commit 
list.

--

Philip


```

## Derrick Stolee, 2019-02-18 19:41

Subject: Re: How to get next commit that just after a specified commit
Message-ID: <8f4bc4cf-cfe4-ddf5-cee3-294ebc5fc88c@gmail.com>
URL: https://gitlist.dev/e/8f4bc4cf-cfe4-ddf5-cee3-294ebc5fc88c%40gmail.com
In-Reply-To: <87ef8bjrqv.fsf@evledraar.gmail.com>

```
On 2/13/2019 4:36 PM, Ævar Arnfjörð Bjarmason wrote:
> 
> On Wed, Feb 13 2019, Junio C Hamano wrote:
> 
>> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> 
> Their point in comparing it to git is that there's nothing intuitive in
> the UI that exposes this information for the *current* graph, whereas in
> fossil this is a built-in command:
> https://fossil-scm.org/xfer/help/descendants
> 
> Perhaps this information is cheaper to extract these days with the
> commit graph and we could expose it somehow?

I believe the recent changes (collected in commit-reach.c) that improve
'git branch --contains' or 'git tag --contains' are important in helping
this descendants list. There is likely more work to be done to show this
list in a rev-list call.

Thanks,
-Stolee 

```
