0

I recently noticed that I've accidentally been using the sign-off feature in msysgit to sign several commits with an incorrect e-mail address. Unfortunately, I have already pushed the commits to my GitHub repository.

Is there any way to remove (or at least replace) the incorrect e-mail address from all commit messages? I'd prefer leaving no traces of the incorrect e-mail at all.

I've already tried replacing every occurrence of e-mail address in every file in the .git directory and its sub-directories, and pushed the changes using git push --force --tags origin 'refs/heads/*', but it didn't seem to work.

NOTE: I am the owner of the GitHub repository. It's currently a private project; no one else is working on it.

osvein
  • 625
  • 2
  • 10
  • 31
  • 1
    Changing this will rewrite the commits, which is likely to cause confusion for people who have pulled from your repository and applied local changes on their side. The new commits will be condiered different than the old ones. If you want to go ahead with it anyway, have a look at [`git filter-branch`](https://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html). – Sven Marnach Feb 07 '15 at 18:34
  • https://help.github.com/articles/changing-author-info/ – Joe Feb 07 '15 at 18:35
  • @AndrewC I don't want to change the author of the commit, I want to change the commit message. – osvein Feb 07 '15 at 18:39
  • 1
    Sorry misread. You want http://stackoverflow.com/questions/19636750/git-filter-branch-msg-filter-to-reword-a-pushed-commit-message – Andrew C Feb 07 '15 at 18:44
  • @AndrewC Thanks, just what I was looking for! I guess my research skills could use some improvement.. – osvein Feb 07 '15 at 18:53

1 Answers1

-1

You will need to use filter-branch

git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "<Old Name>" ];
        then
                GIT_COMMITTER_NAME="<New Name>";
                GIT_AUTHOR_NAME="<New Name>";
                GIT_COMMITTER_EMAIL="<New Email>";
                GIT_AUTHOR_EMAIL="<New Email>";
                git commit-tree "$@";
        else
                git commit-tree "$@";
        fi' HEAD `

If you are the ONLY user who committed to this repository you can simply update all references without checking the old content

git filter-branch -f --env-filter '
    GIT_AUTHOR_NAME="Newname"
    GIT_AUTHOR_EMAIL="newemail"
    GIT_COMMITTER_NAME="Newname"
    GIT_COMMITTER_EMAIL="newemail"
  ' HEAD
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • And then push using the same method as before? – osvein Feb 07 '15 at 18:44
  • the best thing is to delete the branch and re-add it again, as you said no else is working on it so no hard will be done. – CodeWizard Feb 07 '15 at 18:49
  • what is the difference between force pushing and delete/recreate? Is there some github feature, which cares about the difference? – michas Feb 07 '15 at 20:41
  • The OP's question was not immediately clear to me, but appears to be about the signed-off-by (only), not the author and committer email, so rather than `--commit-filter` or `--env-filter`, the best filter would be `--msg-filter`. (However, the commit filter can do anything.) – torek Feb 07 '15 at 22:40