You want to change the author/committer for a range of commits.
Not recommended
Running git filter-branch results in a dire warning about a glut of gotchas generating mangled history
Most powerful
Downloading and using git-filter-repo takes some time, but it does the job.
export ORIGINAL_CLONE_URL=$(git remote get-url origin)
git-filter-repo --name-callback 'return name.replace(b\"Wrong Name\", b\"New Name\")' --force
git-filter-repo --email-callback 'return email.replace(b\"wrong@example.com\", b\"new@example.com\")' --partial --refs A..B --force
git remote add origin $ORIGINAL_CLONE_URL
Easiest
By far the easiest way is using regular rebase together with --exec command to run automatically.
git rebase -i --root --exec 'git commit --amend --reset-author --no-edit'
Notes:
-
--rootmeans the beginning of the repo. You can replace it withHEAD~5for the most recent 5 commits, or a rangeA^..B(check range withgit log A^..Bfirst) -
--reset-authoruses whatever is configured in git. You can also use:--author="New Name <new@example.com>"- or
-c user.name="New Name"and-c user.email="new@example.com"
Check your work
To make both author and committer visible:
FORMAT=" Commit: %h %d %n \
Author: %an <%ae> %n \
Committer: %cn <%ce> %n \
Subject: %s %n"
git log --format="$FORMAT"
Top comments (0)