1

I've seen from Change the author and committer name and e-mail of multiple commits in Git how to change my email in my commits; however, when I try to push it, I get this error:

$ git push production master
To git@<remote_server>
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@<remote_server>
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

So then I tried to execute the commit-email-changing-command in the remote repo and it shows me You need to run this command from the toplevel of the working tree.

Community
  • 1
  • 1
Gio Borje
  • 20,314
  • 7
  • 36
  • 50

1 Answers1

2

All you need to do is use git push --force to overwrite the branch in the remote repository.

Note that this is a bad idea if other people have long-term branches based the current contents of the remote repository. In that case, you shouldn't modify the history at all.

However, short term branches that are thrown away and regenerated often, and never merged back into the upstream branch (like linux-next which is automatically regenerated daily and used only for automatic testing), should be no problem at all.

Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
  • There's only another committer on this repo that I know personally. Will he have any issues if the push is forced? Can he just git-pull normally? – Gio Borje Jan 17 '11 at 21:52
  • 2
    When he does a git-pull, all of his old history with the old email addresses will be merged with all of your new rewritten history (I don't know what kind of conflicts that will entail), and when he pushes again, you'll have both versions of the history in the repository. If you can coordinate with him to throw away his old repository and make a brand new clone, it could work, but if he has other improvements at the moment, he'll lose those. **So give up now, and don't do it. Just use the new email address for new commits, and leave the old commits alone.** – Ken Bloom Jan 17 '11 at 22:03