157

I looked in my git logs and found that the AuthorDate and CommitDate is slightly different for some of my commits. From the git log --pretty=fuller output:

commit 3a5912f90dc5227f308e99f95152fbee2301c59a
Author:     <hidden>
AuthorDate: Fri Jun 15 10:57:22 2012 +0800
Commit:     <hidden>
CommitDate: Fri Jun 15 11:14:37 2012 +0800

The Author and Commit is the same (me).

How does this happen? I have been puzzled for days.

There are more - it happened in 17 out of 341 commits:

+------------------------------+-------------------------------+
| from_unixtime(authored_date) | from_unixtime(committed_date) |
+------------------------------+-------------------------------+
| 2012-06-15 10:57:22          | 2012-06-15 11:14:37           |
| 2012-06-15 14:39:54          | 2012-06-15 14:48:57           |
| 2012-06-19 12:28:21          | 2012-06-19 12:29:41           |
| 2012-06-21 18:16:25          | 2012-06-21 18:28:48           |
| 2012-06-26 17:30:54          | 2012-06-26 17:33:55           |
| 2012-07-13 11:41:43          | 2012-07-13 11:42:17           |
| 2012-07-13 11:56:02          | 2012-07-13 12:13:22           |
| 2012-07-13 12:05:09          | 2012-07-13 12:12:24           |
| 2012-07-12 18:38:49          | 2012-07-13 12:26:35           |
| 2012-07-13 11:00:47          | 2012-07-13 12:25:15           |
| 2012-07-16 14:10:54          | 2012-07-16 14:15:01           |
| 2012-07-13 12:56:51          | 2012-07-16 13:49:48           |
| 2012-07-16 14:10:54          | 2012-07-16 14:19:46           |
| 2012-07-24 16:05:05          | 2012-07-24 16:05:48           |
| 2012-07-24 17:42:58          | 2012-07-24 17:43:33           |
| 2012-07-24 17:42:58          | 2012-07-24 17:45:18           |
| 2012-07-26 16:55:40          | 2012-07-26 16:55:53           |
+------------------------------+-------------------------------+
IMSoP
  • 89,526
  • 13
  • 117
  • 169
Fish Monitor
  • 4,155
  • 3
  • 32
  • 53
  • Hmm, it seems like happening when merging branches. – Fish Monitor Aug 08 '12 at 03:32
  • 2
    Related: http://stackoverflow.com/questions/18750808/difference-between-author-and-committer-in-git – Ciro Santilli OurBigBook.com Apr 14 '17 at 08:36
  • 2
    One unexpected side-effect of having these two different dates: `git log` by default shows only the Author commit date. But if you use `--since`, `--until`, `--before`, `--after`, relative dates, git uses the Committer commit date instead! `git log --since="yesterday"` may not show the expected results if the *Author* commit date is different from the *Committer* commit date. – SherylHohman Apr 15 '20 at 21:20
  • 1
    About whether merging could be altering the dates, it may depend on whether merge is configured in some non-default way that modifies commits. For example, `git --squash merge` is a somewhat common merge strategy that may be configured (although it doesn't look like it's being used here, it's brought up for the sake of example). Also, if git is being used through an IDE or git GUI, there's the possibility of configuration/functionality not present in the CLI. It may be worth double-checking what your merge is configured to do in the environment you perform the merge in. – George Pantazes Jul 08 '20 at 18:27
  • Can you please show the `git log --format=` command you used to generate the first chunk of code-formatted output in your question? – Gabriel Staples Mar 07 '22 at 18:25
  • Nevermind. @TTT [told me here](https://stackoverflow.com/questions/71384830/how-to-make-git-log-show-only-the-commit-date-nothing-else/71384831?noredirect=1#comment126178271_71385517), so I updated the question to make it known. You used `git log --pretty=fuller`. – Gabriel Staples Mar 07 '22 at 18:30

3 Answers3

228

The author date notes when this commit was originally made (i.e. when you finished the git commit). According to the docs of git commit, the author date could be overridden using the --date switch.

The commit date gets changed every time the commit is being modified, for example when rebasing the branch where the commit is in on another branch (more).

Same could happen if you make your commit and send your patch to another one in order to apply the patch in another repo: the author date will be the date of your git commit, the commit date will be set to that date when the patch is applied in the other repo.

If you send the patch to two colleagues, there will be one author date but two different commit dates.

This is also mentioned in the Git Book:

You may be wondering what the difference is between author and committer. The author is the person who originally wrote the patch, whereas the committer is the person who last applied the patch. So, if you send in a patch to a project and one of the core members applies the patch, both of you get credit — you as the author and the core member as the committer

x-yuri
  • 16,722
  • 15
  • 114
  • 161
eckes
  • 64,417
  • 29
  • 168
  • 201
  • Will my case happen when merging branches? – Fish Monitor Aug 08 '12 at 04:40
  • 4
    No. I believe the date is part of the SHA, so unless you perform some operation that rewrites history, like rebasing, it should not change. – asmeurer Aug 08 '12 at 04:53
  • 5
    A brief description of how we should expect the timestamps to change after a cherry-pick, after amending, or rebasing ancestors of the commit would be duly appreciated. Playing around with `git show -s --format="commit %cD author %aD" HEAD`, it would seem that, for instance, amending the commit message with `git gui` updates both, but `git commit --amend` only updates the committer date. unintuitive. – init_js Feb 02 '17 at 10:36
41

The author date on a commit is preserved on rebase / cherry-pick etc. But the commit date is changed.

Michael Anderson
  • 70,661
  • 7
  • 134
  • 187
4

I happened to be in a situation where github showed different commit times from git log and I thought this was a bug with Github.

Turns out github shows the CommitDate and git log shows the AuthorDate (without the fuller flag).

This happened because I cherry-picked two commits from a different branch. While cherry picking the commit timestamps change just like when doing commit --append.

Git rebase retained the commit date in my case.

Also to check the AuthorDate and the CommitDate in git log use --format=fuller Docs

Rishav
  • 3,818
  • 1
  • 31
  • 49
  • Thanks so much for this explanation! I noticed this months ago and couldn't figure out the discrepancy until I read your explanation. The `--format=fuller` flag is awesome, I never knew about that! – slow-but-steady Aug 30 '21 at 01:40