最近在使用gitlab时,遇到报错
GitLab: You cannot push commits for 'my_wrong@email.adress' . You can only push
commits that were committed with one of your own verified emails.
原因是git config中设置的作者邮箱与gitlab中设置的作者邮箱不符,导致了gitlab禁止上传。如果想要push到gitlab中,需要将有问题的commit的作者信息进行修改。修改步骤如下:
- 首先通过git log确定想要修改最近的几个commit信息
- 使用指令
git rebase -i HEAD~2
,注意将2换成自己想要修改的commit的个数,之后将每个commit前面的pick修改为edit,保存并退出 - 使用
git commit --amend --author="作者 <邮箱@xxxx.com>" --no-edit
指令对commit的作者信息进行修改,需要注意的是,这条指令只能修改第一条commit,而非所有需要修改的commit。 - 使用指令
git rebase --continue
,将刚刚修改的一次commit进行提交 - 重复第3、4步,直到将所有commit都修改完成
- 使用
git push
推送到远程仓库