I recently realized that in a Github repository that I use for work, my commits are not associated with my Github account but just show my name without any link. I figured out this is because I had my email set in git to my work email, but my Github account is associated with my personal email. I have changed my email in git, but I wanted to try to change the author on all my past commits so they'd all show as my Github account. I found this StackOverflow question and I used this command from the answer since no one other than me has touched this repository:
git rebase -r --root --exec "git commit --amend --no-edit --reset-author"
However when I pushed this back to Github, it now shows a duplicate of every commit dated today with my Github account as an author, while all the previous commits are still there. How can I clean up this mess? At this point I wouldn't mind just somehow removing all these duplicate commits and going back to having the commit history not be linked to my account.
CodePudding user response:
At this point I wouldn't mind just somehow removing all these duplicate commits and going back to having the commit history not be linked to my account.
Actually, you can have multiple email addresses associated with your GitHub account. Therefore I would add the additional email to your account if you want those commits linked, and reset your repo back to how it was:
git switch main # or whatever branch name is applicable for you
git reset --hard previous-commit-id-before-the-rebase
git push --force-with-lease
Note the --force-with-lease
instead of --force
. If that errors, you'll need to fetch first and see what someone else added, and then decide how to handle it before proceeding.