Git推送错误:预期的提交者电子邮件“ xxxx”,但发现“ yyyy”

时间:2019-07-11 13:34:11

标签: git push

执行git push时出现以下错误:

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'

我的全局配置具有正确的电子邮件地址:

user.email=j.c@xxxx.com

当我执行git日志并检查错误中提到的提交时:

70f23668f033dd59daa116a23c6e63dc0342890f

996b28e37a6ae63d79decd8a773a555913d0fa4e

我可以看到正确的电子邮件地址:

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

在服务器端检查电子邮件地址为

j.c@xxxx.com

似乎在某个时候使用错误的电子邮件地址j.c@yyyy.com进行了提交,现在需要对其进行修改,但我不知道它在哪里或如何执行。有任何想法吗?谢谢。

1 个答案:

答案 0 :(得分:0)

正如Alderath所指出的,问题出在提交者的电子邮件而不是作者。

我使用了以下代码:

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

如以下答案所示,更正所有分支上所有提交的电子邮件:How to change the author and committer name and e-mail of multiple commits in Git?