Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the date of commits in git log out of order?

Tags:

git

When I do a 'git log', why is the date of the commits out of order?

I am looking at 1 branch of my repository. the date should be in order, right?

like image 691
michael Avatar asked Nov 01 '12 13:11

michael


People also ask

What is the order of git log?

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 do I change the last commit date?

Just do git commit --amend --reset-author --no-edit . For older commits, you can do an interactive rebase and choose edit for the commit whose date you want to modify.

How do I update commit history?

There are many ways to rewrite history with git. Use git commit --amend to change your latest log message. Use git commit --amend to make modifications to the most recent commit. Use git rebase to combine commits and modify history of a branch.

Does git commit timestamp?

There are actually two different timestamps recorded by Git for each commit: the author date and the commit date. When the commit is created both the timestamps are set to the current time of the machine where the commit was made.


2 Answers

There's no guarantee that the dates should be in any order. In fact, you can easily forge dates with Git.

Most likely, though, this is due to rebasing or cherry-picking. E.g., what I often do is commit some work locally, then git pull --rebase. The result is that history is rewritten so that my commits are now children of the commits that were introduced in origin/master in the meantime, but git rebase does not change the date of the commits in the process. git cherry-pick has the same effect.

If you want to see the dates at which changes were commited, you can do git log --pretty=fuller to see the CommitDates as well as the AuthorDates. These are more likely to be in order, but even here, there's no guarantee.

like image 117
Fred Foo Avatar answered Sep 23 '22 04:09

Fred Foo


No, not necessarily.

Git tracks two dates. The author date says when the original author made the commit. In the case of email patches it might be taken from an email date. The patch might be applied at a much later time.

The commit date is often in order as that says when a commit is made, and a commit can only be made when its parent exists. If a commit is rebased or cherry-picked it will be given a new commit date but the original author date will be preserved. However, even the commit date is taken from the local system time of the machine where it is made so it is subject to whatever the local clock happened to be set to. In general there's no guarantee that this will be accurate or consistent across machines.

(Both dates include timezone information.)

like image 20
CB Bailey Avatar answered Sep 23 '22 04:09

CB Bailey