threads / discuss / 64695

How Does "git log --reverse" Work?

Subject: How Does "git log --reverse" Work?

## tl;dr

2 messages between Dec 30, 2025 and Dec 30, 2025.

replies: 1people: 2as markdown or json

Jon Forrest· Dec 30, 2025, 00:18 UTC · lore

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· Dec 30, 2025, 02:04 UTC · re: Jon Forrest · lore

Re: How Does "git log --reverse" Work?

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.

← back to recent threads