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

时间:2020-8-27 作者:admin

目录

1. 需求

2. 实现

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

git clone  –bare 解释

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

git push –mirror 解释


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 <directory> and placing the administrative files in <directory>/.git, make the <directory> 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.

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。