Getting the cannot push commits as they contain a private email address error when trying to push

I’m still struggling with the cannot push commits as they contain a private email address error when I try to push 3 commits to my GitHub repo. I want to use a local user.email address, which I forgot to set before making the commits to my local repo.

I’ve set the local user.email address to GitHub’s NoReply email address. How to I correct the 3 commits so that they’ll have the local email address. (I want to leave the global user.email address unchanged.)

Checkout each commit, then: git commit --amend --reset-author

That won’t work with a simple checkout of the commits, because it’d essentially create a new detached head each. What would work is to do git rebase -i, setting all the commits with the wrong mail address to edit, and then amend each in turn. :wink:

Note that an amend with --reset-author also resets the timestamp, if you don’t want that you may have to use the slightly more complex --author=<author> option.

I’m sorry, @airtower-luna, I’m lost. I’ve never done a rebase before and I’ve no idea how to apply a rebase to each commit in turn. (I’m not as concerned about maintaining the timestamp. I’ll just do the rebase starting with the oldest commit going sequentially through to the youngest.)

The Git book has a good description in the Rewriting History chapter. If you do an interactive (that’s what the -i is for) rebase and mark those three commits as edit it’ll walk you through them in turn, that way amending each before continuing the rebase is all that’s needed.

Thank you @airtower-luna for the reference. I’ve run the git rebase -i HEAD~4 command. It put me into some sort of text editor within my PowerShell prompt. But I have absolutely no idea what this editor is, how to work with it, etc. For example, I was trying to change the first commit from pick to edit. Somehow, it’s all gone, and it refuses to allow me to type in edit. I don’t know what to do now.

1 Like

Here are some resources to help with Interactive Rebase:

2 Likes