'Can you order git log by commit timestamp?

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!

git


Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Community
Solution 3