# How Does "git log --reverse" Work?

2 messages from 2025-12-30 to 2025-12-30. Participants: Jon Forrest, Junio C Hamano.
Thread: https://gitlist.dev/t/64695

## Jon Forrest, 2025-12-30 00:18

Subject: How Does "git log --reverse" Work?
Message-ID: <16fc8ecb-01f7-4056-be58-e3aa20345f77@gmail.com>
URL: https://gitlist.dev/e/16fc8ecb-01f7-4056-be58-e3aa20345f77%40gmail.com

```
I'm trying to understand how 'git log --reverse' displays
commits in reverse order (i.e. oldest commit first).

The fact that each commit object has pointer(s) to parent
object(s) makes it trivial to go newest to oldest.
But, I haven't found a way to go oldest to newest.

I've looked at the code but it's not well commented.
Does the answer have something to do with commit lists?

Any advice would be appreciated.

Cordially,
Jon Forrest


```

## Junio C Hamano, 2025-12-30 02:04

Subject: Re: How Does "git log --reverse" Work?
Message-ID: <xmqqy0mkhghx.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqy0mkhghx.fsf%40gitster.g
In-Reply-To: <16fc8ecb-01f7-4056-be58-e3aa20345f77@gmail.com>

```
Jon Forrest <nobozo@gmail.com> writes:

> I've looked at the code but it's not well commented.
> Does the answer have something to do with commit lists?

What revision.c:get_revision() does should be fairly obvious.

When the .reverse option is in effect, it grabs all the commits it
needs to show (with the usual traversal, as if .reverse were not in
effect, by calling get_revision_internal()), queues it in the
.commits list, goes into the reverse output stage, where we output
what we queued earlier.  After that, we yield commits from that
queue.

```
