38

So I recently rebased a branch and merged it into master. When I do git log, I get a pretty, linear history of commits. But I want to see my commit history based on timestamp so I can easily compare when the commits on two branches were made in realtime.

Is there a git log option that can order commits by timestamp instead of their normal commit history? I can't seem to find one. Thanks!

Tim Park
  • 2,446
  • 2
  • 11
  • 13

3 Answers3

44

I was pretty sure it was possible using only git commands but I cannot find it now. --author-date-order does not work for me on rebased branch, as suggested in another answer.

So one way to do that would be to use git log pretty=format: ... to print the commit date in ISO format and let sort or sort -r fix the order.

For example:

git log --pretty=format:"%ad %h by %an, %s" --date=iso | sort -r | less

This will print the ISO date, the hash, the author and the message of the commit and sort it with the latest commits first.

You will find more format options at the PRETTY FORMATS section of git log --help if you need more information per commit.

Thibault D.
  • 10,041
  • 3
  • 25
  • 56
23
git log --author-date-order

This command sorts by author's timestamp instead of commit's timestamp

--author-date-order

Show no parents before all of its children are shown, but otherwise show commits in the author timestamp order.

Community
  • 1
  • 1
Diego Ruiz
  • 257
  • 1
  • 5
  • 7
    What's the difference between author timestamp and commit timestamp? Shouldn't they be the same? – Tim Park Mar 18 '16 at 16:39
  • This worked for me in a repo into which I had pulled in commits from another repo. That is a different situation than the OP's. – cxw May 02 '18 at 17:32
  • This answer is straight forward, why has less votes. – pmiranda Dec 14 '19 at 20:01
  • It still can show items out of date order -- "Show no parents before all of its children are shown". So, while useful, this doesn't correctly answer OPs question. – Grant Birchmeier Jan 10 '20 at 21:10
  • For those wondering the difference between author timestamp and commit timestamp, here's a [SO Post: Why git AuthorDate is different from CommitDate?](https://stackoverflow.com/questions/11856983/why-git-authordate-is-different-from-commitdate) – Alexander Nied Jul 21 '21 at 17:10
7

Things might have changed since the question was asked, but in the current git 2.35 there are three different orderings for logs. From the git log help page:

  • --date-order: Show no parents before all of its children are shown, but otherwise show commits in the commit timestamp order.
  • --author-date-order: Show no parents before all of its children are shown, but otherwise show commits in the author timestamp order.
  • --topo-order: Show no parents before all of its children are shown, and avoid showing commits on multiple lines of history intermixed.

The default is --date-order, although --graph implies --topo-order.

With rebased branches, --date-order will sort by when the commits were rebased, while --author-date-order will sort by when they were originally committed.

(Keep in mind though that there are various ways to mess about with timestamps, so they're not entirely reliable.)

ak2
  • 6,629
  • 31
  • 27