Files
gerrit/修复上传问题指南.md
2025-12-22 17:12:39 +08:00

198 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 修复上传问题指南
## 问题分析
1. **未提交的更改**`android-chat-master` 子模块有修改
2. **远程仓库已存在**:需要更新或删除后重新添加
3. **SSH 主机密钥验证失败**:重新安装 Gerrit 后 SSH 密钥改变了
## 解决方案
### 方法一:使用 HTTP推荐最简单
HTTP 方式不需要 SSH 密钥,更简单。
#### 步骤 1处理未提交的更改
```bash
# 查看当前状态
git status
# 选项 A提交所有更改
git add .
git commit -m "Update code before push to Gerrit"
# 选项 B如果不想提交子模块的更改可以暂存
git stash
```
#### 步骤 2更新远程仓库使用 HTTP
```bash
# 删除旧的远程仓库
git remote remove gerrit
# 重新添加(使用 HTTP不需要 SSH
git remote add gerrit http://101.43.95.130:8080/zhini_im
# 验证
git remote -v
```
#### 步骤 3推送代码
```bash
# 切换到主分支(如果需要)
git checkout -b master 2>/dev/null || git checkout master
# 推送代码
git push gerrit HEAD:refs/heads/master
```
### 方法二:修复 SSH 密钥问题(如果想用 SSH
#### 步骤 1删除旧的 SSH 主机密钥
```bash
# 在 Git Bash 中执行
ssh-keygen -R [101.43.95.130]:29418
# 或者手动编辑 known_hosts 文件
# 删除 /c/Users/Administrator/.ssh/known_hosts 文件中第 4 行
```
#### 步骤 2重新添加 SSH 主机密钥
```bash
# 重新连接并接受新的主机密钥
ssh -p 29418 admin@101.43.95.130
# 输入 yes 接受新的主机密钥
```
#### 步骤 3更新远程仓库使用 SSH
```bash
# 删除旧的
git remote remove gerrit
# 添加 SSH 远程仓库
git remote add gerrit ssh://admin@101.43.95.130:29418/zhini_im
# 推送
git push gerrit HEAD:refs/heads/master
```
## 完整操作步骤(推荐使用 HTTP
### 在 Git Bash 中执行:
```bash
# 1. 进入项目目录
cd /d/zhini/zhini_im
# 2. 查看当前状态
git status
# 3. 处理未提交的更改
# 选项 A提交所有更改
git add .
git commit -m "Update code before push to Gerrit"
# 或者选项 B暂存更改如果不想现在提交
# git stash
# 4. 删除旧的远程仓库
git remote remove gerrit
# 5. 添加 HTTP 远程仓库(推荐,不需要 SSH
git remote add gerrit http://101.43.95.130:8080/zhini_im
# 6. 验证远程仓库
git remote -v
# 7. 切换到主分支(如果需要)
git checkout -b master 2>/dev/null || git checkout master
# 8. 推送代码
git push gerrit HEAD:refs/heads/master
```
## 如果推送时提示需要认证
在开发模式下HTTP 推送通常不需要密码,但如果提示:
- **用户名**`admin`(或您注册的用户名)
- **密码**:留空(开发模式不需要密码)
## 处理子模块问题
如果 `android-chat-master` 是子模块,可以:
### 选项 1提交子模块更改
```bash
cd android-chat-master
git add .
git commit -m "Update submodule"
cd ..
git add android-chat-master
git commit -m "Update submodule reference"
```
### 选项 2忽略子模块更改
```bash
# 暂存子模块更改
git stash
# 或者重置子模块
git submodule update --init --recursive
```
## 验证推送
推送成功后:
1. 访问:`http://101.43.95.130:8080/#/admin/projects/zhini_im`
2. 应该能看到项目代码
3. 访问:`http://101.43.95.130:8080/#/q/project:zhini_im`
4. 应该能看到提交历史
## 常见错误处理
### 错误remote gerrit already exists
```bash
# 删除旧的远程仓库
git remote remove gerrit
# 重新添加
git remote add gerrit http://101.43.95.130:8080/zhini_im
```
### 错误Host key verification failed
**解决方案 1使用 HTTP推荐**
```bash
git remote set-url gerrit http://101.43.95.130:8080/zhini_im
```
**解决方案 2修复 SSH 密钥**
```bash
ssh-keygen -R [101.43.95.130]:29418
ssh -p 29418 admin@101.43.95.130 # 接受新密钥
```
### 错误Changes not staged for commit
```bash
# 提交所有更改
git add .
git commit -m "Update code"
# 或暂存更改
git stash
```