Gitlab/GitHub:迁移代码,并保留历史记录


1. 需求

Git仓库地址改变,需要代码迁移,但需要保留之前开发人员的提交记录,方便回溯

2. 实现

第1步:从原地址克隆一份裸版本库

WANGYANFEI+Administrator@wangyanfei MINGW64 /d/JT/java/back
// 克隆一份裸版本库
$ git clone  --bare http://XX.XX.XX.XX/wangyanfei/certificate-end.git
Cloning into bare repository 'certificate-end.git'...
remote:                                                                                                                                                                                                                                                                        remote: Enumerating objects: 1249, done.
remote:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     remote: Counting objects: 100% (1249/1249), done.                                                                                                                                                                                                                                                                       remote:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                remote: Compressing objects: 100% (673/673), done.
remote: Total 1249 (delta 364), reused 1050 (delta 253)
Receiving objects: 100% (1249/1249), 321.04 KiB | 0 bytes/s, done.
Resolving deltas: 100% (364/364), done.

在这里插入图片描述

git clone --bare 生成的文件夹名称会多出一个.git

git clone --bare 解释

–bare

Make a bare Git repository. That is, instead of creating and placing the administrative files in /.git, make the itself the $GIT_DIR.

This obviously implies the -n because there is nowhere to check out the working tree.

Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/.

When this option is used, neither remote-tracking branches nor the related configuration variables are created.

第2步: 以镜像推送的方式上传代码

新的项目仓库需要建好

WANGYANFEI+Administrator@wangyanfei MINGW64 /d/JT/java/back/certificate-end.git                                                                                                                                                                                                (BARE:master)
// 以镜像推送的方式上传代码
$ git push --mirror http://10.0.0.247/jiean/certificate-end.git
Counting objects: 1249, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (562/562), done.
Writing objects: 100% (1249/1249), 321.01 KiB | 0 bytes/s, done.
Total 1249 (delta 364), reused 1249 (delta 364)
remote:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                remote:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              remote: Resolving deltas: 100% (364/364), done.
remote:
remote: To create a merge request for develop, visit:
remote:   http://10.0.0.247/jiean/certificate-end/merge_requests/new?merge_reque                                                                                                                                                                                               st%5Bsource_branch%5D=develop
remote:
remote: To create a merge request for release, visit:
remote:   http://10.0.0.247/jiean/certificate-end/merge_requests/new?merge_reque                                                                                                                                                                                               st%5Bsource_branch%5D=release
remote:
To http://10.0.0.247/jiean/certificate-end.git
 * [new branch]      develop -> develop
 * [new branch]      master -> master
 * [new branch]      release -> release
 * [new tag]         zsquery-v1.0-20200825 -> zsquery-v1.0-20200825
 

git push --mirror 解释

–mirror

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository.

Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end.

This is the default if the configuration option remote. < remote >.mirror is set.

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值