Skip to content

Instantly share code, notes, and snippets.

@zapidan
Last active June 19, 2023 13:21
Show Gist options
  • Save zapidan/69c175416261d9a13fd4 to your computer and use it in GitHub Desktop.
Save zapidan/69c175416261d9a13fd4 to your computer and use it in GitHub Desktop.
Change previous commits author/email with filter-branch
## Make sure your local repo settings are correct
git config --local --list
git config --local user.name "author name"
git config --local user.email "name@example.com"
## Change previous n commits
git rebase -i HEAD~n
# choose the commits to change by adding 'pick' or 'reword' (only for changing the message)
git commit --amend --author="Author Name <email@address.com>"
# change first commit in repo
git rebase -i --root
# change date of commit to now (maintaining author)
git commit --amend --date="$(date -R)"
# change date and author of commit
git commit --amend --reset-author
## Change all commits with --commit-filter. If your local config was wrong
git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "your previous name" ];
then export GIT_AUTHOR_NAME="your New Name"; export GIT_AUTHOR_EMAIL=new.email@example.com;
export GIT_COMMITTER_NAME="your New Name"; export GIT_COMMITTER_EMAIL=new.email@example.com
fi; git commit-tree "$@"'
@LoganTann
Copy link

the last command is so powerful ! thanks for the gist

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