首页 > 其他分享 >Gitlab仓库迁移到新地址的方式

Gitlab仓库迁移到新地址的方式

时间:2023-11-03 14:37:45浏览次数:32  
标签:origin git move 仓库 Gitlab dev MINGW64 sandbox 迁移

方式一  简单代码迁移

简单代码迁移,顾名思义,就是只迁移代码到新的地址,代码在新的地址开不了之前的提交记录。

 1、登录原Gitlab页面,选择要迁移的项目,复制地址

Gitlab仓库迁移到新地址的方式_xml

2、使用git小乌龟克隆项目到本地

 

Gitlab仓库迁移到新地址的方式_xml_02

3、拉却需要的分支出来

Gitlab仓库迁移到新地址的方式_xml_03

4、登录新的Gitlab页面,创建同名的项目

创建项目方式参考:

Gitlab仓库迁移到新地址的方式_sed_04

 

5、克隆新地址的项目到本地并拉取分支

6、把旧项目名目录下的的代码复制到新项目名目录下

Gitlab仓库迁移到新地址的方式_git_05

 

7、进入到新项目名目录下,提交代码并推送。

 

方式二  Gitlab(整个项目)全库迁移

用命令行实现Gitlab上某个项目的全库迁移,包括该项目的各个分支、提交记录以及标签。

1、首先登录到新地址的Gitlab页面,新建一个项目(创建项目方式参考:),这时新建的项目是没有分支的,如图

Gitlab仓库迁移到新地址的方式_sed_06

 

2、点击Git Bash Here 使用命令把旧地址的项目克隆到本地

命令如下:

1 git clone http://*.*.*.*/path/项目名称.git        #旧项目仓库地址
2 cd 项目名称/
3 git branch
4 git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote";done
5 git fetch --all
6 git fetch --tags

执行结果如下:

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ ls        #列出当前路径下文件

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ pwd        #查看当前路径
/d/.zidingyi/move-projects

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ git clone http://10.10.2.66/zeus/sandbox.git        #把远程仓库的项目克隆到本地
Cloning into 'sandbox'...
remote: Counting objects: 252, done.
remote: Compressing objects: 100% (152/152), done.
Receiving objects:  81% (205/252), 2.44 MiB |remote: Total 252 (delta 34), reused 204 (delta 25)
Receiving objects: 100% (252/252), 2.61 MiB | 197.00 KiB/s, done.
Resolving deltas: 100% (34/34), done.

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ ls        #再次查看当前路径下文件,可以看到已经把sandbox这个项目克隆到本地
sandbox/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ cd sandbox/        #进入到项目名目录下

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ ls        #查看该项目路径下的文件
pom.xml  README.md  sandbox-batch/  sandbox-service-api/  src/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git branch -r        #查看远程分支
  origin/HEAD -> origin/master
  origin/dev
  origin/dev_1.0.0
  origin/dev_1.1.0
  origin/dev_1.4.0
  origin/develop
  origin/master

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git branch        #查看本地分支
* master

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote";done        #切换出全部分支
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
Branch 'dev_1.0.0' set up to track remote branch 'dev_1.0.0' from 'origin'.
Branch 'dev_1.1.0' set up to track remote branch 'dev_1.1.0' from 'origin'.
Branch 'dev_1.4.0' set up to track remote branch 'dev_1.4.0' from 'origin'.
Branch 'develop' set up to track remote branch 'develop' from 'origin'.
fatal: A branch named 'master' already exists.

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git branch        #再次查看本地分支,可以看到本地已切出全部分支
  dev
  dev_1.0.0
  dev_1.1.0
  dev_1.4.0
  develop
* master

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git fetch --all        #获取该项目远程库的所有分支及其内容
Fetching origin

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git fetch --tags        #获取该项目远程库的标签

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ ls
pom.xml  README.md  sandbox-batch/  sandbox-service-api/  src/

 3、把本地整个项目打包压缩,移到需要的路径下面,(也可以在当前路径直接提交代码到新地址)

Gitlab仓库迁移到新地址的方式_xml_07

 

 4、点击Git Bash Here 使用命令把代码提交到远程Gitlab库

 命令如下:

1 git remote rename origin old-origin
2 git remote add origin http://*.*.*.*/path/项目名称.git        #项目的新仓库地址
3 git push origin --all
4 git push --tags

执行结果: 

user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test
$ ls
sandbox/

user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test
$ cd sandbox/

user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test/sandbox (master)
$ ls
pom.xml  README.md  sandbox/  sandbox-batch/  sandbox-service-api/  src/

user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test/sandbox (master)
$ git branch
  dev
  dev_1.0.0
  dev_1.1.0
  dev_1.4.0
  develop
* master

user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test/sandbox (master)
$ git remote rename origin old-origin        #将原来的origin重命名一下

user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test/sandbox (master)
$ git remote add origin http://110.110.2.10:8010/zeus/sandbox.git        #指定需要迁移到的目标地址

user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test/sandbox (master)
$ git push origin --all        #推送所有分支及其内容
Enumerating objects: 251, done.
Counting objects: 100% (251/251), done.
Delta compression using up to 4 threads
Compressing objects: 100% (142/142), done.
Writing objects: 100% (251/251), 2.61 MiB | 19.25 MiB/s, done.
Total 251 (delta 34), reused 251 (delta 34), pack-reused 0
remote: Resolving deltas: 100% (34/34), done.
To http://110.110.2.10:8010/zeus/sandbox.git
* [new branch] dev -> dev * [new branch] dev_1.0.0 -> dev_1.0.0
 * [new branch] dev_1.1.0 -> dev_1.1.0
 * [new branch] dev_1.4.0 -> dev_1.4.0
 * [new branch] develop -> develop
* [new branch] master -> master 
user@▒ҿ▒▒▒▒▒▒▒▒▒▒▒▒ MINGW64 /d/old-origin/move-test/sandbox (master) 
$ git push --tags        #推送标签

5、刷新(新地址)Gitlab页面,就可以看到之前的所有分支等信息

Gitlab仓库迁移到新地址的方式_git_08

 

方式三 迁移需要的分支

用命令行实现Gitlab上某个项目的的某个(某几个)分支的全部内容的迁移,具体步骤与方式二相似;参考一路追寻的博客:

1、命令如下:

1 git clone http://*.*.*.*/path/项目名称.git        #项目的旧仓库地址
 2 cd 项目名称/
 3 git branch
 4 git checkout 分支名
 5 git fetch --all
 6 git fetch --tags
 7 git remote rename origin old-origin
 8 git remote add origin http://*.*.*.*/path/项目名称.git        #项目的新仓库地址
 9 git checkout 分支名
10 git push origin --all
11 git push --tags

2、执行结果如下:

克隆旧地址的项目到本地,切出需要的分支:
usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ pwd
/d/.zidingyi/move-projects

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ ls

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$
Cloning into 'sandbox'...
remote: Counting objects: 252, done.
remote: Compressing objects: 100% (152/152), done.
remote: Total 252 (delta 34), reused 204 (delta 25)
Receiving objects: 100% (252/252), 2.61 MiB | 420.00 KiB/s, done.
Resolving deltas: 100% (34/34), done.

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ ls
sandbox/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects
$ cd sandbox/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ ls
pom.xml README.md sandbox-batch/ sandbox-service-api/ src/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git branch
* master

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git branch -r
origin/HEAD -> origin/master
origin/dev
origin/dev_1.0.0
origin/dev_1.1.0
origin/dev_1.4.0
origin/develop
origin/master

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (master)
$ git checkout dev_1.4.0
Switched to a new branch 'dev_1.4.0'
Branch 'dev_1.4.0' set up to track remote branch 'dev_1.4.0' from 'origin'.

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev_1.4.0)
$ ls
pom.xml README.md src/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev_1.4.0)
$ git fetch --all
Fetching origin

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev_1.4.0)
$ git fetch --tags

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev_1.4.0)
$ ls
pom.xml README.md src/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev_1.4.0)
$ git branch
* dev_1.4.0
master

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev_1.4.0)
$ git checkout dev
Switched to a new branch 'dev'
Branch 'dev' set up to track remote branch 'dev' from 'origin'.

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git fetch --all
Fetching origin
usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git fetch --tags

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ ls
pom.xml README.md sandbox-batch/ sandbox-service-api/ src/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git branch
* dev
dev_1.4.0
master

提交代码到新地址的Gitlab仓库:
usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ ls
pom.xml README.md sandbox-batch/ sandbox-service-api/ src/

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git remote rename origin old-origin

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git remote add origin http://10.110.20.10:8086/zeus/sandbox.git        #关联新地址的Gitlab仓库

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git remote -v        #检查是否关联成功
old-origin http://10.120.10.120/zeus/sandbox.git (fetch)        #旧地址
old-origin http://10.120.10.120/zeus/sandbox.git (push)
origin http://10.110.20.10:8086/zeus/sandbox.git (fetch)        #新地址
origin http://10.110.20.10:8086/zeus/sandbox.git (push)

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git push origin --all
Enumerating objects: 245, done.
Counting objects: 100% (245/245), done.
Delta compression using up to 4 threads
Compressing objects: 100% (139/139), done.
Writing objects: 100% (245/245), 2.61 MiB | 17.48 MiB/s, done.
Total 245 (delta 32), reused 243 (delta 31), pack-reused 0
remote: Resolving deltas: 100% (32/32), done.
remote:
remote: To create a merge request for dev, visit:
remote: http://10.110.20.10:8086/zeus/sandbox/merge_requests/new?merge_request%5Bsource_branch%5D=dev
remote:
remote: To create a merge request for dev_1.4.0, visit:
remote: http://10.110.20.10:8086/zeus/sandbox/merge_requests/new?merge_request%5Bsource_branch%5D=dev_1.4.0
remote:
To http://10.110.20.10:8086/zeus/sandbox.git
* [new branch] dev -> dev
* [new branch] dev_1.4.0 -> dev_1.4.0
* [new branch] master -> master

usrname@DESKTOP-C425NA9 MINGW64 /d/.zidingyi/move-projects/sandbox (dev)
$ git push origin --tags
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 147 bytes | 147.00 KiB/s, done.
Total 1 (delta 0), reused 1 (delta 0), pack-reused 0
To http://10.110.20.10:8086/zeus/sandbox.git
* [new tag] 1.1.0 -> 1.1.0

 3、登录Gitlab页面检查所需要的分支是否已经提交

Gitlab仓库迁移到新地址的方式_xml_09

 

逆风的方向,更适合飞翔,我不怕千万人阻挡,只怕自己投降。



标签:origin,git,move,仓库,Gitlab,dev,MINGW64,sandbox,迁移
From: https://blog.51cto.com/u_14346538/8168763

相关文章

  • 一镜到底 ElasticSearch 数据迁移同步技术
    ##简介[CloudCanal](https://www.clougence.com?kw=51cto_20231103)对于[Elasticsearch](https://www.elastic.co/)的支持经历了很多轮迭代,版本一路从6.x,7.x支持到8.x版本,也适配了其纷繁多样的API。因为Elasticsearch是一个相当流行的、实时的、并且具备一定不可替代能......
  • 一镜到底 ElasticSearch 数据迁移同步技术
    简介CloudCanal对于Elasticsearch的支持经历了很多轮迭代,版本一路从6.x,7.x支持到8.x版本,也适配了其纷繁多样的API。因为Elasticsearch是一个相当流行的、实时的、并且具备一定不可替代能力的搜索引擎,所以很有必要对比下市面上我们能够比较容易获得的、免费的数据迁移......
  • 将GitHub上的forked仓库删除
    内容来自DOChttps://q.houxu6.top/?s=将GitHub上的forked仓库删除我开始使用git和GitHub,有一个项目我正在GitHub上关注。我不小心点击了fork它。现在它似乎成了一个新的项目。我对这件事有一些疑问:我知道如果我对我的forked仓库进行提交或其他操作,它将会被更新,但是更新后......
  • XSAN数据恢复-存储空间从XSAN架构迁移到STORNEXT架构时误格式化存储系统的XSAN数据恢
    XSAN数据恢复环境:昆腾存储,MACOS操作系统,存放视频类数据(MXF、MOV等格式文件)。XSAN故障&检测:将存储空间从XSAN架构迁移到STORNEXT架构后,存储空间中数据全部丢失。 故障存储中一共有9个数据卷:1个META信息卷+8个DATA信息卷。北亚企安数据恢复工程师分析META信息卷&读取其中的元信......
  • 阿里云服务器 ubuntu 20.04 执行命令添加apt仓库时报错 安装docker报错
    云服务器ECS初始安装docker报错##############出错时候看下面#####################执行命令添加apt仓库时:sudoadd-apt-repositoryppa:ondrej/php&&sudoapt-getupdate报错:sudo:add-apt-repository:commandnotfound解决办法:先执行:apt-get-yinstallsoftware-pro......
  • Docker打包前端vue代码推送镜像到远程仓库
    Docker打包前端vue代码推送镜像到远程仓库目录Docker打包前端vue代码推送镜像到远程仓库业务场景:......
  • 麒麟KYLINIOS软件仓库搭建01-新创建软件仓库服务器
    原文链接:麒麟KYLINIOS软件仓库搭建01-新创建软件仓库服务器hello,大家好啊,今天给大家带来麒麟桌面操作系统软件仓库搭建的文章01-新创建软件仓库服务器,本篇文章主要给大家介绍了如何在麒麟桌面操作系统2203-x86版本上搭建内网软件仓库源,本系列共有三个内容,欢迎大家浏览分享转发。关......
  • 提交GitLab代码自动触发jenkins运行
    利用jenkins和gitlab的webhook结合,实现提交代码之后,自动触发jenkins的构建1、插件安装首先jenkins需要安装两个gitlab的插件分别为:(GenericWebhookTriggerPlugin)和(gitlab)。安装完成以后jenkins的GenericWebhookTrigger配置Token。2、在gitlab设置webhook设置前先配置一下GitLab......
  • 使用IDEA管理服务器Docker及远程仓库
    目录配置连接Docker服务器及远程仓库连接服务器Docker远程仓库(可选)IDEA管理确保docker服务器已经开启了远程守护进程访问。[1]配置连接Docker服务器及远程仓库连接服务器Docker在IDEADocker配置中填入服务器IP及端口下方提示ConnectionSuccessful即可。tcp://192.1......
  • [ GitLab ] GitLab 版本升级路线
    https://www.cnblogs.com/yeungchie/必须按照下述的版本依次升级,不能越级更新。1414.0.12>14.3.6>14.9.5>14.10.51515.0.5>15.1.6>15.4.6>15.11.131616.0.x>16.1>16.2.x>16.3>latest参考UpgradingGitLab|GitLab......