gitgithubgit-rewrite-historygit-amend

How to remove personal email from git commits after PR has been merged?


On GitHub I've successfully opened a PR on a public repository, which has been recently merged:

My Pull Request (#25)
* Feature 1
* Feature 2
* Bump version

---------

Authored-by: My Username <my.personal@email.me>

My issue is that my personal email is now public available, which is a thing that I absolutely don't want to.

Is there a way to hide it somehow?

So far I tried:

BONUS: I've read that maybe amend might do the trick but still the procedure isn't clear to me. Would it work even on editing infos from already merged commits?

Lastly, do the maintainers of the public repository have the power to change such displayed infos?


Solution

  • How to remove personal email from git commits

    You cannot do this.

    Git allows you to write new commits and re-hang labels so the labels now point to those new commits instead of the old ones, that's normal, but it is simply not possible (not as an authority thing, this is a "because math" thing) to actually alter existing history. New history will have a different id.

    So git commit --amend writes a new commit with any alterations you like to snapshot, ancestry, message and/or author/committer or timestamps, and re-hangs your branch-tip label on this new commit, abandoning the old one in your current repository. The old commit is still there. Git will eventually get around to garbage-collecting it if it's unreachable through any other reference or reflog for long enough and the repo looks to Git's quick checks like it could use a nice tidy-up.

    You particularly can't do this in other people's repositories. Their repositories are theirs, you send a letter to someone, that letter is theirs. It's not yours any more. You have no, zero, not any, zip, zilch, no way to alter the histories in their repositories that they don't go out of their way to set up for you.

    The most you can do is ask them to abandon your mistakenly-pushed history, and hope nobody has fetched it into their own repositories in the meantime. If you've got force-push rights to the branches they merged your history to you can do the abandoning yourself, but for instance I think GitHub keeps a record of PR tips, and I'm not 100% certain but I think you'll have to have personal assistance from GitHub staff to erase those.

    Pushing to a public repo is publishing on a globally-accessible hosted server explicitly intended for global redistribution. Probably best you just treat this as "lesson learned".