Git - Change history commits of an user
To set up right name and email in the future for commits, you need run command:
git config --global user.name "username"
git config --global user.email "[email protected]"
or put this in ~/.gitconfig file.
If you want to FIX pervious unauthored commits:
gith show
to show WHICH WRONG email has been used.- Create a bare cllone of repo:
git clone --bare https://github.com/username/repo.git
- Replace OLD_EMAIL, CORRECT_NAME, CORRECT_EMAIL after
cd
to the repo and save this script in yourrepo.git
with namechange_user.sh
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct 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
run command: chmod +x change_user.sh && ./change_user.sh
- Force push to Github:
git push --force --tags origin 'refs/heads/*'