Update email address of a series of commits

Hi there, hope you can guys help me with something... I completely reinstalled everything on my machine and got a new fresh setup. This includes git configuration, so when I resumed work on an old project I had to enter my user and email address for all my commits, as expected. Unfortunately I got the email address wrong and now my commits won't appear on the GitHub counter which is a bit of a bummer. Is there a way to overwrite all commits to use a different email address? Git is still one of those things that I only know at the surface level, and I'm still green when it comes to this type of stuff. If it makes a difference, I'm the only one working on this as it's a personal side project so I'm okay with any "drastic" solutions... so long they don't involve erasing the whole commit history 😄 Thanks!
1 Reply
Joao
JoaoOP•2y ago
Mmm what do you mean uninstall the account? I can change the git config on my machine which I've already done, but the commit history on this project already shows the wrong email address I used before that. Not too many, actually, I count about ~30 commits or so, and I only realized once I uploaded to GitHub and noticed the commits were not being counted 😅 I've searched online and looks like git rebase is the command I need for this, but I have little experience making this sort of changes and I don't want to destroy anything that's why I'm asking for some advice first. I don't know if I can revert and re-commit, but I imagine this is even more dangerous as it would also revert my changes? And it's been uploaded to GitHub as well so there are essentially two places I need this change to synchronize... I think I will try git rebase and see what happens. Better lose changes now than 3 monhts from now right? 😄 All right, so I wanted this solved so I went ahead and tried this answer here, and it worked! https://stackoverflow.com/questions/34850831/change-git-email-for-previous-commits I only changed one thing instead of counting the number of commits and use how many commits from the HEAD to edito, turns out that providing the commit hash will apply the changes to all commits from HEAD up to that commit. So the command I used is:
git rebase -i <commit_hash> -x git --amend --author 'Author Name <author email>' --no-edit
git rebase -i <commit_hash> -x git --amend --author 'Author Name <author email>' --no-edit
I just need to also update the other branches but shouldn't be too difficult. I also had to do a git push --force to sync up with GitHub, and now it's reading the commits made correctly Thanks again for the help!
Want results from more Discord servers?
Add your server