Created
March 18, 2024 09:38
-
-
Save AlyxPink/44dc3d4d72d520a344a316de3a109eca to your computer and use it in GitHub Desktop.
A far from perfect script helping you out to rewrite your author name and email in the git history of your repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/bin/bash | |
# Please don't trust me, I made this thing in a hurry and I'm not a Git expert. | |
# I copy pasted stuff from here and there, quickly read some git documentation and | |
# made some trial and error locally. | |
# I've noticed that for some repositories it did not work, and also some commits went from "Verified" to "Unverified". | |
# I'm not sure why, I'm not sure how to fix it, the public keys match sooooo. That's an issue for future me. | |
# Create a mailmap in ~/.config/git/.mailmap (or anywhere else as long as you use it in the next command): | |
# | |
# Pattern is: New Name <new.email@bestdomain.tld> Old Name <oldemail> | |
# You can add as many aliases as you want, one per line | |
# I had multiple Git Author name and even email addresses. It was messy. | |
# You might have more or less lines that I do. | |
# | |
# Alyx <github@alyx.pink> Old FirstName OldLastName <OldEmail> | |
# Alyx <github@alyx.pink> OldFirstName/Variant OldLastName <OldEmail> | |
# Alyx <github@alyx.pink> Alyx <oldEmail> | |
# Alyx <github@alyx.pink> Alyx Pink <OldEmail> | |
# Example: Alyx <github@alyx.pink> Foo Bar <foo.bar@example.com> | |
# Update all your commits following the matches in the mailmap files. | |
# If someone else made a commit, it should not be touched. | |
git filter-repo --force --mailmap ~/.config/git/.mailmap | |
# Re-sign every commits with my new identity | |
git filter-branch --force --commit-filter 'if [ "$GIT_COMMITTER_EMAIL" = "github@alyx.pink" ]; | |
then git commit-tree -S "$@"; | |
else git commit-tree "$@"; | |
fi' -- --all | |
# Update the remote for each repo | |
git remote add origin git@github.com:AlyxPink/$(basename $(pwd)) | |
# Display log to check if everything is fine | |
git log --show-signature | |
# Push everything after a confirmation | |
read -p "Push all with force? (ctrl+c to cancel)" && git push --all --force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment