Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you order git log by commit timestamp?

Tags:

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!

like image 592
Tim Park Avatar asked Mar 16 '16 20:03

Tim Park


People also ask

How do I find the timestamp of a commit in Git?

Wrong! In the commit logs, Git displays the timestamp in the format localtime + timezone offset. When reading the timestamps it’s important to take the timezone offset into account. Using the timezone offset you can convert the timestamp of the Commit 2 and Commit 3 into the UTC time in order to compare them.

What is the default order of Git logs?

By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first. As you can see, this command lists each commit with its SHA-1 checksum, the author’s name and email, the date written, and the commit message.

How to use git log command in Git?

We can use git log command in order to list, filter, view commit history in different ways. In this tutorial we will examine git log command usage in detail with examples. We will start with git log command without any parameter. This will list all commit history in a interactive terminal where we can see and navigate.

How to view changes of a single commit in git log?

And, if you just want to view the changes of a single commit from the log, you can copy the hash and run git show: Just having a list of commits can be messy to sort out branches. Luckily git log provides the --graph option which can be used alongside some


2 Answers

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.

like image 126
Thibault D. Avatar answered Oct 25 '22 07:10

Thibault D.


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.

like image 36
Diego Ruiz Avatar answered Oct 25 '22 08:10

Diego Ruiz