为什么 git AuthorDate 与 CommitDate 不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11856983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:20:43  来源:igfitidea点击:

Why git AuthorDate is different from CommitDate?

git

提问by Fish Monitor

I lookup my git logs and find that the AuthorDate and CommitDate is slightly different for some of my commits:

我查找我的 git 日志,发现 AuthorDate 和 CommitDate 对于我的一些提交略有不同:

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 am puzzled for days.

这是怎么发生的?我困惑了好几天。

There are more(happens in 17 out of 341 commits):

还有更多(发生在 341 次提交中的 17 次):

+------------------------------+-------------------------------+
| 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           |
+------------------------------+-------------------------------+

回答by eckes

The author datenotes 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 --dateswitch.

作者日期笔记时,这个原本承诺作出(即当你完成了git commit)。根据 的文档git commit,可以使用--date开关覆盖作者日期。

The commit dategets 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.

如果您提交并将补丁发送给另一个库以在另一个存储库中应用补丁,则可能会发生同样的情况:作者日期将是您的日期git commit,提交日期将设置为应用补丁时的日期另一个回购。

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:

Git Book 中也提到了这一点:

You may be wondering what the difference is between authorand committer. The authoris the person who originally wrote the patch, whereas the committeris 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

您可能想知道authorcommitter之间的区别是什么。的作者是谁最初写补丁的人,而提交者是谁最后应用补丁的人。因此,如果您向项目发送补丁并且其中一个核心成员应用了该补丁,那么你们双方都会获得荣誉——您是作者,核心成员是提交者

回答by Michael Anderson

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

提交的作者日期保留在 rebase/cherry-pick 等上。但提交日期已更改。