一个提交对象如何会有两个作者?

8

提交 487128950df6ee433c131b5feaafe81ee86629f4 可在 https://github.com/signalwire/freeswitch.git 找到。

git log -1 487128950df6ee433c131b5feaafe81ee86629f4 --pretty=fuller 命令输出:

commit 487128950df6ee433c131b5feaafe81ee86629f4
Author:     Travis Cross <tc@traviscross.com>
AuthorDate: Fri Mar 21 06:12:02 2014 +0000
Author:     Anthony Minessale <anthm@freeswitch.org>
AuthorDate: Fri Mar 14 02:59:13 2014 +0500
Commit:     Travis Cross <tc@traviscross.com>
CommitDate: Mon Mar 24 12:54:50 2014 +0000

    Use the system version of APR / APR-util if possible

    Autodetect whether the system libapr / libaprutil has our
    necessary modifications and use it if it does.

这个提交有2个作者。如果fsck检查开启,将此提交推送到Gitlab或Github可能会失败,并抱怨“remote:error:object 487128950df6ee433c131b5feaafe81ee86629f4:multipleAuthors:invalid format-multiple 'author' lines”。
我很好奇这个提交是如何创建的。记录多个作者的一个解决方案是在提交消息中添加“Co-authored-by”。由于可以创建具有两个作者的提交,为什么没有内置方法呢?为什么git fsck认为这样的提交是坏对象?

4
请注意2014年的日期:当时,Git没有进行太多的一致性检查(或者也许人们认为Git应该允许多个作者行)。有很多类似的历史奇怪之处,这就是为什么git fsck有那么多配置条目来确定任何特定错误是硬错误还是警告的原因。 - torek
1个回答

7

一个Git提交对象就是一个压缩的文本文件。这个提交对象恰好有两个作者。

$ pigz -d < .git/objects/48/7128950df6ee433c131b5feaafe81ee86629f4 
commit 438tree 070633dfc3ea352dfb1094822f477111e519a9ca
parent cde20f6fe68523d9416d2fed72435a8ba880a269
author Travis Cross <tc@traviscross.com> 1395382322 +0000
author Anthony Minessale <anthm@freeswitch.org> 1394747953 +0500
committer Travis Cross <tc@traviscross.com> 1395665690 +0000

Use the system version of APR / APR-util if possible

Autodetect whether the system libapr / libaprutil has our
necessary modifications and use it if it does.

我很好奇这个提交是如何创建的。

你需要向Travis Cross询问他们具体是如何创建它的。 创建一个提交只不过是将文本写入文件,并没有更复杂的操作。

为什么git fsck认为这样的提交是坏对象?

在内部,Git每个提交只能有一个作者。允许多个作者需要重新设计内部结构。

虽然git-log会显示多个作者,但这可能是一种实现技巧。其他工具将不会同时记录两个作者。例如,git shortlog --group=author只计数提交到Anthony Minessale。

如果需要多个作者,请通过“合作作者” "trailers"添加协作者。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接