I've started to work on some projects in the past without giving my correct GitHub email address in the credentials of git from Terminal. So every commit was showed as follows:
These commits are made without my user name so these commits are also not showing in the contributions section:
As it is shown in image 1 that I've made a commit on March 14 but it is not shown in the contributions (because of the wrong email was set for the git credentials). Now I all my latest contributions are shown correct but I also want all the old contributions of my past projects to be shown like this. But I don't want to change the history of commits (i.e. date).
We can use .mailmap
to write all the commits but I think this is a bit difficult solution.
The simpler solution that I found very useful is as follows:
--> First of all, use git shortlog -sne
into your project directory to check all the users' commits with their emails.
Now, if your project has the only user that is used for commits, then you should try this:
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='newName'
GIT_AUTHOR_EMAIL='newEmail'
GIT_COMMITER_NAME='newName'
GIT_COMMITER_EMAIL='newEmail'
" HEAD
Remember:
If your project has multiple contributors, it'll also update that to just one contributor that you will provide.
--> For multiple contributors, where you want to update one or specific contributor. You can try the conditional approach, e.g.
git filter-branch -f --env-filter "
if test "$GIT_AUTHOR_EMAIL" = 'currentWrongEmail'
then
GIT_AUTHOR_EMAIL='newEmail'
fi
if test "$GIT_COMMITTER_EMAIL" = 'currentWrongEmail'
then
GIT_COMMITTER_EMAIL='newEmail'
fi
" HEAD
At the end of both cases, use git push -f
to update the remote repository instantly.