A safer alternative to git's filter-branch
is filter-repo
tool as suggested by git docs here.
git filter-repo --commit-callback '
old_email = b"[email protected]"
correct_name = b"Your Correct Name"
correct_email = b"[email protected]"
if commit.committer_email == old_email :
commit.committer_name = correct_name
commit.committer_email = correct_email
if commit.author_email == old_email :
commit.author_name = correct_name
commit.author_email = correct_email
'
The above command mirrors the logic used in this script but uses filter-repo
instead of filter-branch
.
The code body after commit-callback
option is basically python code used for processing commits. You can write your own logic in python here. See more about commit
object and its attributes here.
Since filter-repo
tool is not bundled with git you need to install it separately.
See Prerequisties and Installation Guide
If you have a python env >= 3.5, you can use pip
to install it.
pip3 install git-filter-repo
Note: It is strongly recommended to try filter-repo
tool on a fresh clone. Also remotes are removed once the operation is done. Read more on why remotes are removed here. Also read the limitations of this tool under INTERNALS section.