# Default ordering of git log output

2 messages from 2015-09-03 to 2015-09-03. Participants: Kirill Likhodedov, Junio C Hamano.
Thread: https://gitlist.dev/t/40262

## Kirill Likhodedov, 2015-09-03 13:50

Subject: Default ordering of git log output
Message-ID: <494BA1BD-150F-45A2-BF5D-9A933D9C1344@gmail.com>
URL: https://gitlist.dev/e/494BA1BD-150F-45A2-BF5D-9A933D9C1344%40gmail.com

```
Is it intended behavior that the default git log output (without ordering parameters) can show parents before children? 

The man says:
    Commit Ordering
       By default, the commits are shown in reverse chronological order.
so it tells nothing about parent-to-child relationship.

I‘ve just faced an example in an open source repository, where I reproduced this behavior: a parent is shown before its child. (so if this behavior is not intended I can give the project URL for debugging)

So could you please clarify:
1. Is it true that the rule "no parents before all of its children are shown” is not guaranteed for default ordering?

2. What does "reverse chronological order” mean? How commits are actually sorted in git log? 

// I was always under impression that git log lists commit in the order in which they are “recorded" to the repository (e.g. pulled), since this seems to be both the fastest way, and also pretty acceptable from the ordering point of view.  

Thanks a lot!
-- Kirill.

```

## Junio C Hamano, 2015-09-03 16:43

Subject: Re: Default ordering of git log output
Message-ID: <xmqqk2s7lagq.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqk2s7lagq.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <494BA1BD-150F-45A2-BF5D-9A933D9C1344@gmail.com>

```
Kirill Likhodedov <kirill.likhodedov@gmail.com> writes:

> Is it intended behavior that the default git log output (without
> ordering parameters) can show parents before children?
>
> The man says:
>     Commit Ordering
>        By default, the commits are shown in reverse chronological order.
> so it tells nothing about parent-to-child relationship.

When you do not give order and when your traversal is not "limited"
(i.e. you do not specify A in "git log A..B" that tells us where the
traversal ends in topological sense), the traversal "git log" goes:

 - We put HEAD to a queue that holds commits that are further to be
   processed.

 - We pick up the youngest commit from the queue; we show it, and
   push its parents that haven't been shown to the queue.  We repeat
   this step until the queue runs out items.

Your history, when a project participant uses a broken clock to
record the committer timestamp, could look like this (topology flows
from left to right):

           1---5---6
          /   /
     2---3---4

where the labels in the illustration depict the relative order of
their committer timestamps.  Imagine your HEAD is at '6'.

So "git log" would do

    Queue       Action
    6           show 6, push 5 to the queue
    5           show 6, push 1 and 4 to the queue
    4 1         show 4, push 3 to the queue
    3 1         show 3, push 2 to the queue
    2 1         show 2; nothing pushed (as it is root)
    1           show 1; nothing is pushed (as its parent 3 has
                        already been shown)
    -empty-

```
