0

I've been using the wrong email while making commits to my repo.

I found [this script][1] that let me replace the faulty commits. It did work, but the original faulty commits are still there.

So now instead of 15 faulty commits, the repo has 15 faulty + 15 correct commits.

1 Answers1

0

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
  • I am the only contributor, but I will keep that in mind. Will this remove the duplicate commits my repo has? –  Oct 09 '19 at 15:55
  • Nope, it will not remove the older commits. read here how to "move back" to the commit before your changes and then execute it from this point. https://stackoverflow.com/questions/34519665/how-to-move-head-back-to-a-previous-location-detached-head-undo-commits/34519716#34519716 – CodeWizard Oct 09 '19 at 16:03