When I run git log --oneline
for example, it outputs a list of commits in chronologic order (descendent). My question is: What criteria git uses to sort this list? Does it use the author_date
or the committer_date
to order the result? Or it uses another? This can be an issue for me if it sort by committer_date
as this attribute can change over time. I appreciate any help about this.

- 3,352
- 3
- 32
- 38
-
1As an extra note : try adding `--graph` to your `git log` commands to have a better view of how commits are ordered -- for example : to view the difference between `--date-order` and `--topo-order` – LeGEC Mar 13 '20 at 14:22
1 Answers
Actually the primary sort criterion is given by the parent-child relationships, which are always respected in log listings (if three commits are chained A->B->C
they will never be displayed in A C B
order, no matter the dates or the log options).
But when we are displaying commits from paralell branches, there is some freedom in the ordering.
For this scenario, there exist the options --date-order --topo-order
. And here, "date-order" (the default) means the committer_date
. If you wish to sort by the author date, there is the additional option --author-date-order
.
If you are listing commits from a single branch, then these options are irrelevant.
Doc: https://git-scm.com/docs/git-log#_commit_ordering
---1----2----4----7
\ \
3----5----6----8----9--
Suppose you have this commit history (copied from docs) where the horizontal coordinate corresponds to the (author) date. Then the log list will display:
date-order topo-order topo-order (alt)
9 9 9
8 8 8
7 6 7
6 5 4
4 3 2
5 7 6
2 4 5
3 2 3
1 1 1
More info here

- 73,180
- 20
- 142
- 190
-
topological is the default behavior? because in the docs it says "By default, the commits are shown in reverse chronological order." – Savrige Mar 13 '20 at 13:43
-
1
-
let me see if a got it: if I want to traverse only commits in **one** branch (let's say master branch), it will follow the parent-child relationship order. But if I want to traverse all commits considering **n** possible branches, it will default to date-order (commiter_date) as the order criterion? I'm not considering here using additional options, just want to know the default behavior of git log. – Savrige Mar 13 '20 at 14:28
-
1Not exactly. The commits in each (sub)branch are first ordered by parent-child. Then, paralell braches are intermixed by commiter_date order. See the figure in https://git-scm.com/docs/git-log#_commit_ordering – leonbloy Mar 13 '20 at 14:47
-
This answer incorrect. In order for log listings to respect the parent child relationships, `--topo-order` must be used. Otherwise `git log master` would return exactly the same result as `git log master --topo-order`. But, in reality, the results differ. – gilly3 Dec 21 '20 at 19:47