git将其他库中的代码导入到新库

将老库的代码导入到新库

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
  • 修改远程仓库地址,把 originoldCode.git 改成 newCode.git

  • 之后,所有 pushpull 操作都会指向 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,并且可以在新仓库继续开发和管理代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值