Last active
August 13, 2022 11:41
-
-
Save bitIO/a2435fbabb439cd2868c1275fa2e5f0e to your computer and use it in GitHub Desktop.
How to rewrite history in a git repo
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/sh | |
## change commits | |
####################################################### | |
git filter-repo --commit-callback ' | |
msg = commit.message.decode(\"utf-8\") | |
newmsg = msg.replace(\"old string\", \"new string\") | |
commit.message = newmsg.encode(\"utf-8\") | |
' --force | |
## change commiter - filter-repo | |
####################################################### | |
cd repo | |
git filter-repo --mailmap my-mailmap | |
#my-mailmap file content | |
Correct Name <[email protected]> <[email protected]> | |
## change commiter - filter-branch | |
####################################################### | |
git filter-branch --env-filter ' | |
OLD_EMAIL="[email protected]" | |
CORRECT_NAME="Your name" | |
CORRECT_EMAIL="[email protected]" | |
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] | |
then | |
export GIT_COMMITTER_NAME="$CORRECT_NAME" | |
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" | |
fi | |
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] | |
then | |
export GIT_AUTHOR_NAME="$CORRECT_NAME" | |
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" | |
fi | |
' --tag-name-filter cat -- --branches --tags -f | |
git push --force --tags origin 'refs/heads/*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From https://help.github.com/articles/changing-author-info/