Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing git author info on all commits worked on one of my repos but not the others, why?

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?

like image 514
bigdaveygeorge Avatar asked Jan 04 '20 11:01

bigdaveygeorge


2 Answers

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 run

git 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]")'
like image 104
VonC Avatar answered Jan 05 '23 01:01

VonC


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/*'
like image 36
bigdaveygeorge Avatar answered Jan 05 '23 01:01

bigdaveygeorge