gitlab项目迁移到gerrit--百分百不会出错的解决终极报错的最后版本

发布时间:2024年01月23日

1、在Gerrit上新建项目

2、Gerrit项目配置权限(此处非代码,实在不会配或者报错就给全部的权限)

Reference:refs/*
Push Annotated Tag
Push Signed Tag
Forge Committer Identity
Create Reference
Read
Push

# ssh生成密钥,别问为啥不是rsa的,因为可能会由于ssh版本而报错`在这里插入代码片`
[root@docker tmp]# ssh-keygen -t ed25519

# 获取公钥
[root@docker tmp]# cat /root/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICKEgoJg3IfbXu+Ay1b+3ZTXBPk1Dwxb7YvmPraEcY5Z root@docker

# 添加公钥到gerrit
登录Gerrit, Settings -> SSH Public Key -> Add Key

# 测试连接gerrit
[root@docker tmp]# ssh -p 29418 keke.shan@10.10.1.99

  ****    Welcome to Gerrit Code Review    ****

  Hi keke.shan, you have successfully connected over SSH.

  Unfortunately, interactive shells are disabled.
  To clone a hosted Git repository, use:

  git clone ssh://keke.shan@gerrit.xinyunkeji.com:29418/REPOSITORY_NAME.git
  
# 拉取gitlab的项目
[root@docker tmp]# git clone http://gitlab.xinyunkeji.com/TXX_Group/TXX-V355.git

# 进入
[root@docker tmp]# cd TXX-V355

# 拉下来所有的分支,你也可以查看分支后手动拉取
[root@docker TXX-V355]# for line in `git branch -a | grep remotes | cut -d'/' -f3|grep -v HEAD`
do
    git checkout ${line}
    git pull
done

# 修改地址为gerrit远程仓库地址(一定要用ssh去连接)
[root@docker TXX-V355]# git remote set-url origin ssh://10.10.1.99:29418/TXX_Group/TXX-V355
# http连接可能会报错如下
error: RPC failed; result=22, HTTP code = xxx
fatal: The remote end hung up unepectedly 

# 提交所有分支,这里会失败,查了下好像是本地master和远程gerrit冲突
[root@docker TXX-V355]# git push --all
...
 ! [rejected]          master -> master (fetch first)
error: failed to push some refs to 'ssh://10.10.1.99:29418/TXX_Group/TXX-V355'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

# 允许不相关历史提交,并强制合并
[root@docker TXX-V355]# git pull origin master --allow-unrelated-histories

# 重新提交到远程仓库
[root@docker TXX-V355]# git push origin master

# 提交所有的tag
[root@docker TXX-V355]# git push --tags
文章来源:https://blog.csdn.net/Mico18/article/details/135772003
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。