I have various private GitHub repos and use Sublime Merge to manage my commits.
I want to change all the previous commit author details:
From Name: This, Email: [email protected]
To: Name: That, Email: [email protected]
I have therefore followed these instructions from GitHub and amended the code to the following:
#!/bin/sh
git filter-branch -f --env-filter '
CORRECT_NAME="That"
CORRECT_EMAIL="[email protected]"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
' --tag-name-filter cat -- --branches --tags
On one of the repos this worked and before I used git push --force --tags origin 'refs/heads/*'
from the instrucitons Sublime Merge showed the potential changes and after running the push all the commits were now updated to the desired details.
All good, so I thought, until I tried this with several of my other repositories and no change shows in sublime and the push does nothing. I have no idea why there is a difference. The other repositories are similar in the fact they all have the same original committer.
Why does this not work for the other repos and how can I fix to allow me to do the changes?
A better option would be to use the new tool git filter-repo
, which replaces BFG and git filter-branch
.
See its user manual.
To modify username and emails of commits, you can create a mailmap file in the format accepted by
git-shortlog
.
For example, if you have a file named my-mailmap you can rungit filter-repo --mailmap my-mailmap
and if the current contents of that file are as follows (if the specified mailmap file is version controlled, historical versions of the file are ignored):
Correct Name <[email protected]> <[email protected]>
then we can update username and/or emails based on the specified mapping.
See git shortlog
"mapping author" section for the exact syntax of a mailmap file.
Or, with callbacks:
git-filter-repo --name-callback 'return name.replace(b"OldName", b"NewName")' \
--email-callback 'return email.replace(b"[email protected]", b"[email protected]")'
I figured this out looks I wasn't including both AUTHOR
and COMMITTER
details:
In terminal within repo directory:
git filter-branch -f --env-filter "GIT_AUTHOR_NAME='New Name'; GIT_AUTHOR_EMAIL='[email protected]'; GIT_COMMITTER_NAME='New Name'; GIT_COMMITTER_EMAIL='[email protected]';" HEAD
Then:
git push --force --tags origin 'refs/heads/*'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With