0

When doing a git push I get the following error:

remote: Push rejected.
remote:
remote: refs/heads/features/PLA-1458: 70f23668f033dd59daa116a23c6e63dc0342890f: expected committer email 'j.c@xxxx.com' but found 'j.c@yyyy.com'
remote:
remote: refs/heads/features/PLA-1458: 996b28e37a6ae63d79decd8a773a555913d0fa4e: expected committer email 'j.c@xxxx.com' but found 'j.c@yyyy.com'
remote:
remote:
To https://www.company.net/stash/scm/abc/123.git
 ! [remote rejected] features/PLA-1458 -> features/PLA-1458 (pre-receive hook declined)
error: failed to push some refs to 'https://www.company.net/stash/scm/abc/123.git'

my global config has the correct email address:

user.email=j.c@xxxx.com

when I do a git log and check the commits that are mentioned in the error:

70f23668f033dd59daa116a23c6e63dc0342890f

and

996b28e37a6ae63d79decd8a773a555913d0fa4e

I can see the correct email address:

commit 70f23668f033dd59daa116a23c6e63dc0342890f 
Author: J C <j.c@xxxx.com> 
Date:   Tue Jun 18 10:08:50 2019 +0200

commit 996b28e37a6ae63d79decd8a773a555913d0fa4e 
Author: J C <j.c@xxxx.com> 
Date:   Fri Jun 14 16:18:44 2019 +0200

Checking on the server side the email address is

j.c@xxxx.com

it looks like at some point a commit was made with the wrong email address j.c@yyyy.com and it needs to be amended now, but I dont know where it is or how to do it. Any ideas? thanks.

Jon
  • 766
  • 1
  • 9
  • 27
  • https://stackoverflow.com/questions/3042437/how-to-change-the-commit-author-for-one-specific-commit/28845565 may be the solution you are looking for. – Matt Weber Jul 11 '19 at 13:37
  • 1
    The error message says committer email, not author email. Did you try using `git log --pretty=fuller` to print both author and committer information? Alternatively, you could use `git cat-file -p ` to print the raw contents of the commit object. – Alderath Jul 11 '19 at 13:41
  • aha! you are right I can see the committer email now on those commits being the wrong one. now, how do I change them? – Jon Jul 11 '19 at 13:45

1 Answers1

0

As noted by Alderath the problem was the Commiter email, not the author.

i used this code:

git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

to correct the email on all commits on all branches as shown in this answer: How to change the author and committer name and e-mail of multiple commits in Git?

Jon
  • 766
  • 1
  • 9
  • 27