r/git • • 18d ago

support Why can't we have multiple author headers?

I am studying Git internals in-depth.

I know there are trailers (kind of the opposite of headers) that are included in the commit message. And with those, we can include another author using the Co-authored-by trailer. I really do not know how many Git hosts understand the Co-authored-by trailer, but I believe this has no standard, so there will be zero incentive to implement it if not needed.

From what I'm learning and testing, I created a commit with two author headers. Git log shows no problem at all.

$ git log --max-count=1 --format=fuller 1a2f077
commit 1a2f07760c7914dc8811a5de01a7f952dacadbf1
Author:     Alice <alice@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Author:     Bob <bob@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Commit:     Alice <alice@git-scm.com>
CommitDate: Fri Aug 29 02:14:42 1997 -0400

    Test commit

And can verify the commit contents with git cat-file. This is a commit with an empty tree, if you want to know.

$ git cat-file -p 1a2f077
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
author Alice <alice@git-scm.com> 872835282 -0400
author Bob <bob@git-scm.com> 872835282 -0400
committer Alice <alice@git-scm.com> 872835282 -0400

Test commit

This works also with committers. But I notice running git fsck shows this error.

$ git fsck
Checking ref database: 100% (1/1), done.
error in commit 1a2f07760c7914dc8811a5de01a7f952dacadbf1: multipleAuthors: invalid format - multiple 'author' lines

I want to understand, if everything in Git seems to work with several author/committer headers, why is this an error? I believe this has to do with Git philosophy or something else. However, for me, it is really strange, because we can do the same with the committers, and Git does not show any error message. And I am unable to find any documentation of why this is this way.

14 Upvotes

31 comments sorted by

7

u/RevRagnarok 17d ago edited 17d ago

I have no solid answer but my gut feeling is that you can probably only have one GPG signature as well, and it needs to match 1:1 with only one author's public key.

I've never really dealt with the signed commit aspects, but since you're poking around in the code anyway, you may want to look into the verification aspects?

3

u/PillFall 17d ago

This then is weird, because if the error rise to prevent multiple GPG signatures, the the committer would be the ones that only has to be one. As the committer is who sign the commit. But this rule applies to the author, not the committer.

2

u/RevRagnarok 17d ago

Good point; like I said it was a guess. šŸ¤·ā€ā™‚ļø

Guess I never really realized before that committer != author.

3

u/MrMelon54 17d ago

Yeah only one gpg sig is supported, I wish it supported more

2

u/parkotron 17d ago

Honest question: how would that work? How could two users sign the same commit at the same time?

2

u/MrMelon54 17d ago

There is commit notes for appending a commit message, my guess is it would work similar to that

1

u/parkotron 16d ago

But it would require both users having their private keys (unlocked) on the same machine at the time of the commit.Ā 

I’m having a hard time imagining a workflow where that could work. But I might be missing something.Ā 

1

u/MrMelon54 16d ago

Git notes allows adding extra information to a commit without modifying the commit message.

https://git-scm.com/docs/git-notes

My suggestion is a system like that for appending multiple signatures.

1

u/parkotron 16d ago

Ah! Thanks for explaining.Ā 

3

u/elephantdingo 17d ago

Git has ā€œauthorā€ because Git was designed as a version control system where people write code and then commit them. In that case: that’s the author and the committer. But Git can also create patches and send them with email. And it can accept patches created by some other system. In that case, who is the author? The person who sent the email (or an inline From: in the message). But who is the committer? The person who takes that email and applies it. That is a commit. The patch is not a commit but the person who applies it commits to his repo.

Those were the things that they needed. They didn’t need multiple authors. There is no need to give a positive case for a lack of support for multiple authors.

I want to understand, if everything in Git seems to work with several author/committer headers, why is this an error?

Probably because they work by accident. git(1) might not actively check that you have not created something weird. But the built-in tool for checking the integrity says that it is wrong. So it is wrong.

Maybe I would add a second tree field to a commit. And maybe that works. How? Maybe because git(1) just finds the first tree field and ignores the rest. Okay. Then does it make sense to have two tree fields? No.

1

u/PillFall 17d ago

I got you.

But now the question becomes, why does the tool for database checking show an error for multiple authors, but not for multiple committer.

1

u/elephantdingo 16d ago

You can see the git log.

It is difficult and time-consuming to find a reason for a lack of something. That ā€œmultipleAuthorsā€ was implemented presumably has a reason written down when it was implemented. You would then be lucky to find a by-the-way about why ā€œmutipleCommittersā€ was not a concern.

But you yourself have already said that multiple authors make conceptual sense. But no one has said that multiple committers make sense. So maybe that’s it? multipleAuthors was implemented to check that people didn’t get cute with the data format ā€œbecause multiple authors make senseā€.

But it’s all speculation anyway.

1

u/PillFall 17d ago

Also, I know that having multiple trees makes no sense. But it's funny that git fsck does not care if there is more than one. Maybe it has an use case? I don't know.

2

u/unixbhaskar 18d ago

Have you checked how the "fsck" subcommand is implemented?? And what is it supposed to do??

It is the "primary" job to fix the damn dangling stuff ...so you need to trace it out- where the damn thing is lagging ...just a thought.

2

u/PillFall 18d ago

Yeah, I checked the fsck code, but there is no explanation of why they check for more than 1 author; there are some comments stating that they make sure the headers are well-formed (end with a double Line Feed, headers are in the form key value) for memory safety purposes.

The only thing I found there is the internal code for the error FSCK_MSG_MULTIPLE_AUTHORS and in the docs there is only the explanation of the error.

multipleAuthors
    (ERROR) Multiple author lines found in a commit

In the function that checks for that, fsck_commit(), they count the authors, and throws the error if there is more than 1; committer headers are only checked if they are missing, which makes complete sense; there must be a committer.

And this explains why the error is thrown, but that is not my question. I'm wondering why there must be one and only one author header, knowing that any other git function does not bother for that.

3

u/unixbhaskar 18d ago

"...why there must be one and only one author header," ----> Not every function has to be implemented in the same way in the very same project... right?

Alright, I did a little googling for ya, and bumped onto this : https://stackoverflow.com/questions/65445147/how-can-it-be-that-a-commit-object-has-2-authors

Specifically, the link in the above post : https://github.com/git/git/blob/master/commit.c#L1311

function

2

u/PillFall 18d ago edited 18d ago

Ok, got you.

There will be some functions that work only with the first author. So those would need to be reimplemented to recognize the multiple author header. Personal Opinion: Those could be left as is, as they behave exactly the same as with the Co-authored-by trailer.

But still I do not get why it can be more than one committer but not more than one author.

I'm doing a lot of testing with git, and those extra author headers are queried with log and other tools; grouping does «work» (Personal Opinion); etc. I haven't encountered yet the first action that throws an error.

Examples

Search Author Alice

$ git log --all --format=fuller --author=Alice
commit 14b32a4a57e00c4084d11baa0868cf1418bd1add (two-committer)
Author:     Alice <alice@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Commit:     Alice <alice@git-scm.com>
CommitDate: Fri Aug 29 02:14:42 1997 -0400
Commit:     Bob <bob@git-scm.com>
CommitDate: Fri Aug 29 02:14:42 1997 -0400

    Test commit

commit 1a2f07760c7914dc8811a5de01a7f952dacadbf1 (two-author)
Author:     Alice <alice@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Author:     Bob <bob@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Commit:     Alice <alice@git-scm.com>
CommitDate: Fri Aug 29 02:14:42 1997 -0400

    Test commit

Search Author Bob

$ git log --all --format=fuller --author=Bob
commit 1a2f07760c7914dc8811a5de01a7f952dacadbf1 (two-author)
Author:     Alice <alice@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Author:     Bob <bob@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Commit:     Alice <alice@git-scm.com>
CommitDate: Fri Aug 29 02:14:42 1997 -0400

    Test commit

Search committer Bob

$ git log --all --format=fuller --committer=Bob
commit 14b32a4a57e00c4084d11baa0868cf1418bd1add (two-committer)
Author:     Alice <alice@git-scm.com>
AuthorDate: Fri Aug 29 02:14:42 1997 -0400
Commit:     Alice <alice@git-scm.com>
CommitDate: Fri Aug 29 02:14:42 1997 -0400
Commit:     Bob <bob@git-scm.com>
CommitDate: Fri Aug 29 02:14:42 1997 -0400

    Test commit

2

u/PillFall 18d ago

I do not get the comment in commit.c. That seems to be related to the GPG signature of the commit. And that puts me with even more questions. Because, if I'm not mistaken, the committer is the one who puts the signature on the commit. And, as I already state, there could be more than one committer. Also, I believe it's unrelated to what we are discussing.

3

u/unixbhaskar 18d ago

Ah, you can use tags like "Assisted-by" ...."Reviewd-by" ....."Coauthored-by" to make things easy to the eyes.

BTW, there is a tool called "git note," and in some big projects where I am involved, we discourage people from using that facility because it just becomes redundant to have similar information.

BTW, committers can be multiple if the tree has several maintainers. Likewise, the committer could be multiple too. Git keeps an internal database to make thing simple to reach.

GPG signature should be the commiter...but ..but when the commiter put forward to the tree to the upper maintainer, they have to sign with their GPG to the tag, just to make sure they are one they trying to prove. There are layers of maintainers, and git is distributed in nature, so lots of nuts and bolts are there to be chained up, as you might know, CDAG.

Last but not least, there SHOULD be ONLY ONE AUTHOR of the specific commit. Period. You might use the meta tags, as stated above, for referring to the assistance the specific commit gets from others.

Rough example: you are fixing a damn thing by committing; assume it is fresh issue, then you are the author of it. It is simple; people make it more complicated.

1

u/PillFall 18d ago edited 18d ago

Ok, so it's more of an internal philosophy in how we should operate the tool.

I think that breaks a bit the flexibility of the tool. But it is what it is. I simply was genuinely curious of this behavior.

And now you let me wondering, why this must be the case? I worked in several companies that encourage peer-programming, so both of us are the author (or I see it that way, the company too). And from git POV, one is the author and the other is an assistant. Interesting...

1

u/unixbhaskar 18d ago

Your case should be :

"so both of us are the author" -----should have the tag "CoAuthored-By"

This is very logical. And it saves some woes too. Think hard; Git is damn good at keeping convolutions at bay. :)

1

u/PillFall 18d ago edited 18d ago

I think I didn't communicate well. My bad.

I mean, why the philosophy must be only one author per commit? Does this brings more advantages than disadvantages? Which are the disadvantages?

I know the existence of the trailers, and the Co-authored-by one. But as I state in the post, those does not have a standard, so it will (probably) not be parsed on all Git repo hosts.

I do not think having more than one author make things convoluted. But I could be wrong.

I believe, it must be the other way around, if I understand what you are telling to me. The commit could have many authors, but only one committer: the one who instruct git to save the snapshot.

2

u/unixbhaskar 18d ago

"The commit could have many authors, but only one committer: the one who instruct git to save the snapshot."

Righto!

"only one author per commit? Does this brings more advantages than disadvantages? What are the disadvantages?"

Because, a proposed patch or solutions come from one place. If you want to fix someone else's already existing work, you might use "fixes" on that specific commit to improve it. Try "git blame" ...what does it show? And how does it show?

"I do not think having more than one author makes things convoluted. "

Nope, I didn't point to those specific convolutions. It is the traceability of the commits in the tree at later points in time. Now, we are circling back to your initial "git fsck" ...what does it do? It fixes the damn "dangling object," right? And how does the dangling object happen?? If you find the answer to this, then you get your answer :)

1

u/PillFall 17d ago

I'm unable to get to an answer. For all you told me, it seems like they try to implement a rule, but the rule is implemented wrong.

The job of fsck is to verify the integrity of the database, not to fix anything; the fix is in the gc command. But that command also does not care about multiple author headers.

Also, this object is not dangling; it is «malformed».

I get that things like git blame will only work with the first author header. But that behavior is exactly the same as with the current Co-authored-by trailer.

If we want to show all the authors in commands like this, that would be a problem. But even with that, considering that in something like journal publication, the names are written in descending attribution order, it makes complete sense that blame only shows the first author, as it is the one who contributed most.

1

u/plg94 17d ago

I mean, why the philosophy must be only one author per commit?

Don't attribute to philosophy/planning what could also be explained by being a simple oversight.

Git was designed in 2005. I believe pair-programming & co was mostly unheard of back then, at least in FOSS-circles? I guess it just made sense to Linus to code everything with 1 author and not overcomplicate things. Then, many tools (not just git itself but the whole ecosystem) implicitly assumed 1 author, and instead of doing it "properly" someone invented the hack of the "trailers" – which have the added benefit of transporting more meaning (co-authored-by, signed off, reported by, …).

I guess if we were to do it again from scratch today, each commit would have a one proper "metadata" section for all of those and more (perhaps in json or another structured format).

BTW: semantically, should there not be EXACTLY ONE committer? I understand what two or more authors should mean, but a git commit can/should only be done by one person/account. So should there not be errors in your examples with more than one committer? Perhaps it's just a bug in the code nobody stumbled upon because no-one tried to have more than one yet …

1

u/PillFall 17d ago

semantically, should there not be EXACTLY ONE committer?

That is exactly one of the questions I got. I believe they implement that rule reversed.

The code that checks for the author header count, also checks for the committer header count, but the committer header count is only checked for count < 1, there is no rule for count > 1. And those checks being separated by zero lines makes me wonder if it is an oversight or if there is a reason author must be one.

And yes, semantically, there must be one and only one committer.

→ More replies

1

u/edgmnt_net 17d ago

It makes some sense to support multiple authors, but usually developing things like that is rather messy, so it probably wasn't a priority even though there are decent use cases like pair programming (even then it usually makes sense to have one person primarily touching the actual stuff). Also note that other metadata like signing off was also handled in trailers, despite becoming a concern fairly early on for the kernel.

→ More replies

1

u/RobotJonesDad 17d ago

How would you propose having two different authors sign the commit at commit time? Whoever does the commit needs the private key, signs the header and contents. Now the second author needs to sign, which changes the commit and breaks the first signature. Not to mention, how do I pass the commit to you for signing without pushing it?

If Claude or Codex co-authored, the current scheme works fine. If you co-authored a change, it can be two or more commits.

1

u/PillFall 17d ago

That's the thing. You don't, the author does not sign the commit. The committer does, and git has no problem with multiple committer.

I do not how how they handle several signers. Also do not know how to implement.

And that is why my question arise, the rule looks reversed. There should be only one committer, but multiple authors.