first commit
This commit is contained in:
161
修复邮箱地址问题.md
Normal file
161
修复邮箱地址问题.md
Normal file
@@ -0,0 +1,161 @@
|
||||
# 修复 Gerrit 推送邮箱地址问题
|
||||
|
||||
## 问题描述
|
||||
|
||||
推送代码时出现错误:
|
||||
```
|
||||
ERROR: commit 356c4cc: email address noreply@gitee.com is not registered in your account
|
||||
```
|
||||
|
||||
这是因为从码云拉取的代码中,提交记录的作者邮箱是 `noreply@gitee.com`,但 Gerrit 要求提交者的邮箱必须在账户中注册。
|
||||
|
||||
## 解决方案
|
||||
|
||||
### 方案一:修改提交记录的作者信息(推荐)
|
||||
|
||||
将所有提交记录的作者邮箱改为已注册的邮箱 `263303411@qq.com`:
|
||||
|
||||
```bash
|
||||
cd /d/zhini/zhini_im
|
||||
|
||||
# 使用 git filter-branch 批量修改所有提交的作者信息
|
||||
git filter-branch --env-filter '
|
||||
OLD_EMAIL="noreply@gitee.com"
|
||||
CORRECT_NAME="renjianbo"
|
||||
CORRECT_EMAIL="263303411@qq.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
|
||||
```
|
||||
|
||||
**注意**:这个命令会重写 Git 历史,如果已经推送到其他远程仓库,需要强制推送。
|
||||
|
||||
### 方案二:只修改最近的提交(如果只有少量提交)
|
||||
|
||||
如果只有最近的几个提交有问题,可以逐个修改:
|
||||
|
||||
```bash
|
||||
cd /d/zhini/zhini_im
|
||||
|
||||
# 修改最后一次提交
|
||||
git commit --amend --author="renjianbo <263303411@qq.com>" --no-edit
|
||||
|
||||
# 如果有多个提交需要修改,使用交互式 rebase
|
||||
git rebase -i HEAD~10 # 修改最近10个提交
|
||||
# 在编辑器中,将要修改的提交前的 'pick' 改为 'edit'
|
||||
# 然后对每个提交执行:
|
||||
git commit --amend --author="renjianbo <263303411@qq.com>" --no-edit
|
||||
git rebase --continue
|
||||
```
|
||||
|
||||
### 方案三:在 Gerrit 中注册邮箱地址
|
||||
|
||||
1. 访问:`http://101.43.95.130:8080/settings#EmailAddresses`
|
||||
2. 添加邮箱地址:`noreply@gitee.com`
|
||||
3. 验证邮箱(如果需要)
|
||||
4. 然后重新推送
|
||||
|
||||
**注意**:通常不推荐注册 `noreply@gitee.com`,因为这是码云的自动邮箱,不是真实邮箱。
|
||||
|
||||
## 推荐操作步骤
|
||||
|
||||
### 步骤 1:检查有多少提交使用了错误的邮箱
|
||||
|
||||
```bash
|
||||
cd /d/zhini/zhini_im
|
||||
|
||||
# 查看所有提交的邮箱
|
||||
git log --format='%H %an <%ae>' | grep -i noreply@gitee.com
|
||||
```
|
||||
|
||||
### 步骤 2:批量修改所有提交(如果有很多提交)
|
||||
|
||||
```bash
|
||||
# 先备份当前分支(可选但推荐)
|
||||
git branch backup-rjb_dev
|
||||
|
||||
# 批量修改所有提交的作者信息
|
||||
git filter-branch -f --env-filter '
|
||||
if [ "$GIT_COMMITTER_EMAIL" = "noreply@gitee.com" ]
|
||||
then
|
||||
export GIT_COMMITTER_NAME="renjianbo"
|
||||
export GIT_COMMITTER_EMAIL="263303411@qq.com"
|
||||
fi
|
||||
if [ "$GIT_AUTHOR_EMAIL" = "noreply@gitee.com" ]
|
||||
then
|
||||
export GIT_AUTHOR_NAME="renjianbo"
|
||||
export GIT_AUTHOR_EMAIL="263303411@qq.com"
|
||||
fi
|
||||
' --tag-name-filter cat -- --branches --tags
|
||||
|
||||
# 清理备份(可选,确认修改正确后)
|
||||
# git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
|
||||
```
|
||||
|
||||
### 步骤 3:重新推送
|
||||
|
||||
```bash
|
||||
# 由于历史被重写,需要强制推送
|
||||
git push gerrit HEAD:refs/for/master --force
|
||||
```
|
||||
|
||||
## 如果使用方案二(只修改部分提交)
|
||||
|
||||
```bash
|
||||
cd /d/zhini/zhini_im
|
||||
|
||||
# 查看提交历史,找到有问题的提交
|
||||
git log --oneline --format='%h %an <%ae>' | head -20
|
||||
|
||||
# 假设要修改最近 5 个提交
|
||||
git rebase -i HEAD~5
|
||||
|
||||
# 在编辑器中,将需要修改的提交前的 'pick' 改为 'edit'
|
||||
# 保存并关闭编辑器
|
||||
|
||||
# 对每个标记为 'edit' 的提交执行:
|
||||
git commit --amend --author="renjianbo <263303411@qq.com>" --no-edit
|
||||
git rebase --continue
|
||||
|
||||
# 重复直到所有提交都修改完成
|
||||
|
||||
# 重新推送
|
||||
git push gerrit HEAD:refs/for/master
|
||||
```
|
||||
|
||||
## 验证修改结果
|
||||
|
||||
```bash
|
||||
# 检查是否还有 noreply@gitee.com 的提交
|
||||
git log --format='%H %an <%ae>' | grep -i noreply@gitee.com
|
||||
|
||||
# 如果没有任何输出,说明所有提交都已修改
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **修改 Git 历史**:`git filter-branch` 会重写 Git 历史,如果代码已经推送到其他远程仓库,需要通知团队成员重新克隆。
|
||||
|
||||
2. **备份**:在执行批量修改前,建议先创建备份分支。
|
||||
|
||||
3. **强制推送**:修改历史后,需要使用 `--force` 推送,但 Gerrit 可能不允许强制推送到 `refs/for/*`,如果遇到问题,可以尝试:
|
||||
```bash
|
||||
git push gerrit HEAD:refs/for/master
|
||||
```
|
||||
|
||||
4. **邮箱配置**:确保本地 Git 配置使用正确的邮箱:
|
||||
```bash
|
||||
git config user.name "renjianbo"
|
||||
git config user.email "263303411@qq.com"
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user