Files
gerrit/解决no_common_ancestry错误.md
2025-12-22 17:12:39 +08:00

158 lines
3.2 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.
# 解决 "no common ancestry" 错误
## 问题原因
本地仓库和远程仓库没有共同的提交历史。Gerrit 创建项目时可能创建了空的初始提交,而本地仓库有不同的历史。
## 解决方案
### 方法一:合并远程历史后推送(推荐)
```bash
cd /d/zhini/zhini_im
# 1. 先拉取远程内容(允许不相关历史)
git fetch gerrit master
# 2. 合并远程历史
git merge gerrit/master --allow-unrelated-histories
# 3. 如果有冲突,解决冲突后:
# git add .
# git commit -m "Merge remote history"
# 4. 推送到评审队列
git push gerrit rjb_dev:refs/for/master
```
### 方法二:直接推送到主分支(如果允许)
```bash
cd /d/zhini/zhini_im
# 1. 提交所有更改(包括子模块)
git add .
git commit -m "Initial push to Gerrit"
# 2. 拉取并合并远程历史
git pull gerrit master --allow-unrelated-histories
# 3. 解决冲突(如果有)
# 然后推送
git push gerrit rjb_dev:refs/heads/master
```
### 方法三:创建新的初始提交(如果远程是空的)
如果远程仓库只有一个空的初始提交,可以创建一个新的提交:
```bash
cd /d/zhini/zhini_im
# 1. 提交所有更改
git add .
git commit -m "Initial push to Gerrit"
# 2. 拉取远程内容
git fetch gerrit master
# 3. 创建一个合并提交
git merge gerrit/master --allow-unrelated-histories -m "Merge Gerrit initial commit"
# 4. 推送到主分支
git push gerrit rjb_dev:refs/heads/master
```
## 完整操作步骤(推荐)
### 在 Git Bash 中执行:
```bash
# 1. 进入项目目录
cd /d/zhini/zhini_im
# 2. 查看远程分支
git fetch gerrit
# 3. 查看远程内容
git log gerrit/master --oneline
# 4. 提交所有更改(包括子模块)
git add .
git commit -m "Initial push to Gerrit"
# 5. 合并远程历史
git merge gerrit/master --allow-unrelated-histories
# 6. 如果有冲突,解决冲突:
# - 编辑冲突文件
# - git add .
# - git commit -m "Merge remote history"
# 7. 推送到评审队列
git push gerrit rjb_dev:refs/for/master
```
## 如果远程是空的(只有初始提交)
可以强制推送,但会覆盖远程内容:
```bash
cd /d/zhini/zhini_im
# 1. 提交所有更改
git add .
git commit -m "Initial push to Gerrit"
# 2. 强制推送到主分支(覆盖远程)
git push gerrit rjb_dev:refs/heads/master --force
```
⚠️ **注意**:强制推送会覆盖远程内容,请确认远程没有重要内容。
## 处理子模块问题
如果子模块 `android-chat-master` 的更改不想提交:
```bash
# 暂存子模块更改
git stash
# 然后执行推送
git push gerrit rjb_dev:refs/for/master
```
## 最简单的解决方案
如果确定要覆盖远程的初始提交:
```bash
cd /d/zhini/zhini_im
# 1. 暂存子模块更改(如果不想提交)
git stash
# 2. 强制推送到主分支
git push gerrit rjb_dev:refs/heads/master --force
```
## 验证推送
推送成功后:
1. **访问项目页面**
```
http://101.43.95.130:8080/#/admin/projects/zhini_im
```
2. **查看代码**
```
http://101.43.95.130:8080/#/admin/projects/zhini_im,general
```
3. **查看提交历史**
```
http://101.43.95.130:8080/#/q/project:zhini_im
```