Skip to contentSkip to conversation

How Does "git log --reverse" Work?

DISCUSSION Jon Forrest 2 participants 2 messages Dec 30, 2025

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 2 lines · Jon Forrest

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.