I am looking to edit the author/committer of several commits whose message is prefixed with [TEST].
I know that you can edit the authors with environment variables but I can't find it by searching with the commit message.
git filter-branch --env-filter '
OLD_EMAIL="oldmail@domain.tld"
CORRECT_NAME="Useername"
CORRECT_EMAIL="newmail@domain.tld"
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
We should be able to integrate a regex like this "[TEST]*":
if commit message = "[TEST]*" then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
Using the third-party git-filter-repo(1):
git filter-repo --commit-callback='
if commit.message.startswith(b"[TEST]") and commit.author_email == b"oldmail@domain.tld":
commit.committer_name = b"Username"
commit.committer_email = b"newmail@domain.tld"
commit.author_name = b"Username"
commit.author_email = b"newmail@domain.tld"
'
This Python callback (see manual) lets you change the commit in-place.
You will need to pass --force
as well in order to do the change because
this is a destructive update that cannot (in general) be undone.
git-filter-branch(1) is effectively deprecated and no one that I've seen has recommended its usage.