37

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!

0

3 Answers 3

43

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.

0
24
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.

5
  • 6
    What's the difference between author timestamp and commit timestamp? Shouldn't they be the same?
    – Tim Park
    Mar 18, 2016 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 2, 2018 at 17:32
  • This answer is straight forward, why has less votes.
    – pmiranda
    Dec 14, 2019 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. Jan 10, 2020 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? Jul 21, 2021 at 17:10
5

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.