Skip to content

Instantly share code, notes, and snippets.

@Krokette
Last active April 8, 2021 02:44
Show Gist options
  • Save Krokette/856da0d2fa6726162577a2fd26b57de4 to your computer and use it in GitHub Desktop.
Save Krokette/856da0d2fa6726162577a2fd26b57de4 to your computer and use it in GitHub Desktop.
Change author username email from previous already pushed commits | history
git filter-branch -f --env-filter '
WRONG_EMAIL="<wrong_email>"
NEW_NAME="<username>"
NEW_EMAIL="<your_email>"
    
if [ "$GIT_COMMITTER_NAME" = "De Backer Christophe" ]

then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi

if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]

then
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags 

Then you need to use git push -f <remote> <branch>

And if I want to delete a commit from the history ?

  1. git log to find the commit you want to remove and copy its hash

  2. git rebase -i <commit_hash>~ which opens your text editor

  3. In text editor, switch from pick to drop for your particular commit

  4. Then you may want to use an git rebase --continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment