Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can it be that a commit object has 2 authors?

Tags:

git

The commit 487128950df6ee433c131b5feaafe81ee86629f4 can be found at https://github.com/signalwire/freeswitch.git.

git log -1 487128950df6ee433c131b5feaafe81ee86629f4 --pretty=fuller prints:

commit 487128950df6ee433c131b5feaafe81ee86629f4
Author:     Travis Cross <[email protected]>
AuthorDate: Fri Mar 21 06:12:02 2014 +0000
Author:     Anthony Minessale <[email protected]>
AuthorDate: Fri Mar 14 02:59:13 2014 +0500
Commit:     Travis Cross <[email protected]>
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.

It has 2 authors. Pushing this commit to Gitlab or Github could fail if fsck check is on, complaining remote: error: object 487128950df6ee433c131b5feaafe81ee86629f4: multipleAuthors: invalid format - multiple 'author' lines.

I'm curious how this commit was created. One of the solutions to record multiple authors is appending Co-authored-by in the commit message. As it's possible to create a commit with two authors, why hasn't it been a built-in method? And why is such a commit considered as a bad object by git fsck?

like image 420
ElpieKay Avatar asked Dec 25 '20 03:12

ElpieKay


People also ask

Can a git commit have multiple authors?

You can attribute a commit to more than one author by adding one or more Co-authored-by trailers to the commit's message. Co-authored commits are visible on GitHub.

What does committed object contain?

Commit object type The commit object contains the directory tree object hash, parent commit hash, author, committer, date and message.


1 Answers

A git commit object is just a compressed text file. This one happens to have two authors.

$ pigz -d < .git/objects/48/7128950df6ee433c131b5feaafe81ee86629f4 
commit 438tree 070633dfc3ea352dfb1094822f477111e519a9ca
parent cde20f6fe68523d9416d2fed72435a8ba880a269
author Travis Cross <[email protected]> 1395382322 +0000
author Anthony Minessale <[email protected]> 1394747953 +0500
committer Travis Cross <[email protected]> 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.

I'm curious how this commit was created.

You'd have to ask Travis Cross for exactly how they did it. Making a commit is not much more than writing text to a file.

Why is such a commit considered as a bad object by git fsck?

Internally, Git can only have one author per commit. Allowing multiple authors would require reworking the internals.

While git-log will display multiple authors that's probably an implementation quirk. Other tools will not honor both authors. For example, git shortlog --group=author only counts the commit to Anthony Minessale.

If you need multiple authors, add co-authors via "trailers".

like image 145
Schwern Avatar answered Sep 29 '22 14:09

Schwern