How to mark a past commit as belonging to another user / why does "Claim email address" not show for others

I (user A) have a commit in one of my public repos which has code that was donated to me by another user (user B), so I committed it via --author. So the commit has committer A, an author that has an email owned by user B, and occurred in a repo owned by user A (me). We both are registered on GitHub.

Turns out however, the email that ended up in the commit that wasn’t the exact one user B uses as main email on GitHub but another one. So therefore, the commit is shown to be made by someone “unknown” and not actually linked to user B on GitHub. This is what I am looking to fix.

Now there is the “Claim email address” button showing up when I (user A) look at that commit, but obviously I didn’t author it but just commit it - that other user (user B) did. So it makes no sense that I would claim the other user’s address, obviously. However, user B does not see the “Claim email address” button, hence cannot claim it. Is this because the commit is in my repo, and somehow linked to commit rights, …?

So what is the button/API/… such that I can either link up the commit to that user B myself, or such that I can enable that user B to press the button on the commit in my repo (user A’s repo) to claim it themselves?

1 Like

In order to do this, you’ll need to rewrite the commit history. To do this, you’ll have to do it from the command line on a local clone of your repository.

If the commit you want to change is the most recent one, then the operation is relatively simple. You can execute:

git commit --amend --author="Mona Octocat <octocat@github.com>"

and replace the example author information above with the corrected author information.

If the commit you want to change is not the most recent commit, then it’s a little more complicated.

:rotating_light: Warning: This is a complicated process and involves rewriting your git commit history. Rewriting git commit history is a potentially lossy operation meaning that it is possible to lose data. Please use caution and back up your repository if you’re uncertain. :rotating_light:

First, you’ll have to identify a commit that is earlier than the one you want to change. So if the hash of the one you want to change starts with 123abcd and the one just before it starts with 456efgh, then you can execute the command:

git rebase -i 456efgh

This will bring up an editor window with a list of commits by hash and commit message. Scroll down the list until you find the commit you want to edit. When you find it, change the text pick to edit, then save and exit the editor.

When you exit the editor, git will begin the rewriting process and stop at the commit that you specified you wanted to edit. When the process pauses, you can then run the git commit --amend command that I showed above to change the author information.

When you’ve rewritten the commit information, you can complete the rebase process by executing git rebase --continue.

Finally, when you’re certain you’ve fixed the commit you can update your repository by force pushing the branch.

:rotating_light: Warning: Force pushing a branch can lose data :rotating_light:

You can force push the branch to the remote repository with:

git push --force

Please let us know if you have any questions and I hope that helps!

@lee-dohm thanks for your response but sadly, your suggestion seems not too relevant to me (and way too destructive that I’d consider it to work around this, since this is a public repo with clones out in the wild). The commit history isn’t wrong, I apologize if that wasn’t clear. It’s just that people, surprise, have multiple e-mails. And since the claim button exists, this seems to be not completely unknown to the GitHub backend either.

So I’ll repeat my original question which seems to be quite unanswered still: how can I make the claim button show up for some other person external to the repo? Or how can I link them up myself with their account to that commit/e-mail? Under which conditions does the claim button show up anyway?

If that really is the case, then how the claiming works really needs a fix, because that isn’t what people should be rewriting history for if it’s otherwise correct. But that does sound bewildering given the claim button does exist after all, it’s just that it doesn’t show up for the right person. Surely I’m not the first to run into this scenario?