将老库的代码导入到新库
D:\project>git clone --bare https://codeup.aliyun.com/oldCode.git template
Cloning into bare repository 'template'...
remote: Enumerating objects: 22005, done.
remote: Counting objects: 100% (22005/22005), done.
remote: Total 22005 (delta 179), reused 15395 (delta 179), pack-reused 0
Receiving objects: 100% (22005/22005), 31.50 MiB | 22.73 MiB/s, done.
Resolving deltas: 100% (179/179), done.
#进入template文件
D:\project>cd template
D:\project\template>git remote set-url origin https://codeup.aliyun.com/newCode.git
D:\project\template>git push origin --tags && git push origin --all
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch.
Everything up-to-date
Enumerating objects: 22005, done.
Counting objects: 100% (22005/22005), done.
Delta compression using up to 8 threads
Compressing objects: 100% (21092/21092), done.
Writing objects: 100% (22005/22005), 31.50 MiB | 5.23 MiB/s, done.
Total 22005 (delta 179), reused 22005 (delta 179), pack-reused 0
remote: Resolving deltas: 100% (179/179), done.
remote: warning: too many references (519 > 100) to update, fallback to atomic push
To https://codeup.aliyun.com/62f23d331d343f24a1808e24/web/multi-tenant-web.git
* [new branch] dev -> dev
* [new branch] feature/20230315_archive -> feature/20230315_archive
* [new branch] feature/20230317_channel_fix -> feature/
解析命令
git clone --bare https://codeup.aliyun.com/oldCode.git template
克隆一个裸仓库(bare repository),存放在
template/
目录下。裸仓库 只包含 Git 版本控制的数据(
refs/
,objects/
,config
等),不包含工作区的代码。这个裸仓库通常用于迁移 Git 代码或作为远程仓库使用。
cd template
进入
template
目录,即你刚刚克隆的裸仓库。
git remote set-url origin https://codeup.aliyun.com/newCode.git
修改远程仓库地址,把
origin
从oldCode.git
改成newCode.git
。之后,所有
push
和pull
操作都会指向newCode.git
。
git push origin --tags
推送所有的 Git 标签(tags)到
newCode.git
远程仓库。
tags
通常用于版本管理(如v1.0.0
)。这样
newCode.git
会拥有oldCode.git
中所有的标签信息。
git push origin --all
推送所有分支到
newCode.git
。由于
template/
是裸仓库,没有默认分支,所以需要手动推送所有分支。
这些操作会发生什么
克隆了
oldCode.git
的裸仓库 到template/
,但不包含实际代码文件。修改了
origin
远程地址,指向newCode.git
。把所有标签(tags)推送到
newCode.git
。把所有分支推送到
newCode.git
,完成代码迁移。
最终结果
newCode.git
现在包含了oldCode.git
的所有分支和标签。我们的代码仓库已经成功迁移到
newCode.git
,并且可以在新仓库继续开发和管理代码。