Skip to contentSkip to conversation

Why does "git log --reverse -1" print the HEAD commit?

DISCUSSION Teemu Likonen 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

It feels wrong that "git log -1" and "git log --reverse -1" both print the same commit: HEAD. Why is that?

Since "git log --reverse" starts from the bottom I'd have expected "-1" to print one commit from the bottom.

#1 lore raw
Quoted 5 lines · Teemu Likonen

It feels wrong that "git log -1" and "git log --reverse -1" both print the same commit: HEAD. Why is that?

Since "git log --reverse" starts from the bottom I'd have expected "-1" to print one commit from the bottom.

-1 limits the commit list to one element and then it prints that range in reverse order, which is the same for a single commit.

#2 lore raw

Miklos Vajna wrote (2008-05-31 16:24 +0200):

Quoted 10 lines
Quoted 5 lines · Teemu Likonen

It feels wrong that "git log -1" and "git log --reverse -1" both print the same commit: HEAD. Why is that?

Since "git log --reverse" starts from the bottom I'd have expected "-1" to print one commit from the bottom.

-1 limits the commit list to one element and then it prints that range in reverse order, which is the same for a single commit.

Oh yeah, that's the logic, thanks. I find it counter-intuitive but I'll survive.