Home Git edit author information for previous commits
Post
Cancel

Git edit author information for previous commits

To rewrite author information such as author usernames and emails for previous commits, first add an alias for the change-commits command.

1
git config --global alias.change-commits '!'"f() { VAR=\$1; OLD=\$2; NEW=\$3; shift 3; git filter-branch --env-filter \"if [[ \\\"\$\`echo \$VAR\`\\\" = '\$OLD' ]]; then export \$VAR='\$NEW'; fi\" \$@; }; f"

To change author name and email address,

1
2
git change-commits GIT_AUTHOR_NAME "old name" "new name"
git change-commits GIT_AUTHOR_EMAIL "old@email.com" "new@email.com"

To specify the number of previous commits to rewrite,

1
2
# e.g. edit past 3 commits
git change-commits GIT_AUTHOR_NAME "old name" "new name" HEAD~3..HEAD

However when you attempt to edit both of them(i.e. more than once), it crashes with the existing backup.

1
2
3
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f

Remove the original backup.

1
git update-ref -d refs/original/refs/heads/<branch-name>

This changes the author without changing the commit date.
However, it does NOT reconfigure the commit author.
rewrite_author


Git, rewrite previous commit usernames and emails

This post is licensed under CC BY 4.0 by the author.

Git store credentials permanently

Docker buildx for multiarchitectural image building