当前位置: 首页 > news >正文

Git仓库迁移到远程仓库(源码、分支、提交)

单个迁移仓库

一、迁移仓库 

1.准备工作
> 手动在电脑创建一个临时文件夹,CMD进入该目录
> 远程仓库上创建一个同名的空仓库

2.CMD命令:拉取旧Git仓库(包含提交、分支、源码)

$ git clone --bare http://git.domain.cn/path/app.git

3.CMD命令:进入本地仓库目录

$ cd app.git

4.CMD命令:推送仓库到新远程仓库(包含提交、分支、源码)

$ git push --mirror https://gitee.com/path/app.git
$ cd ..
二、更改本地项目的仓库地址

1、CMD进入本地项目文件夹(不是刚才拉取的仓库目录,是项目文件夹,如果没有,则直接从新仓库克隆项目源码到本地即可

2、CMD命令:更改为新的仓库地址

$ git remote set-url origin https://gitee.com/path/app.git

以上是单个仓库的命令,如需迁移多个项目,可以参考下面的批量命令。

批量迁移仓库

一、Windows批量迁移Git仓库脚本(源码、分支、提交).bat

使用场景:旧仓库迁移到新仓库,支持所有远程Git仓库。首次运行会弹窗要求输入Git账号密码。

使用方法:把此bat和remotes-all.txt文件放在一个空文件夹里双击运行。

@echo off@REM 旧的仓库地址
set remote_old=http://git.domanin.cn/git-path
@REM 新的仓库地址
set remote_new=http://gitee.com/git-path
@REM 仓库名称列表:手动创建一个remotes-all.txt文件,多个仓库用换行隔开
set input_file=remotes-all.txtSETLOCAL DisableDelayedExpansion
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ %input_file%"`) do (call :process %%a
)
goto :eof:process
SETLOCAL EnableDelayedExpansion
set "repo=!%1!"
set "repo=!repo:*:=!"
echo !repo!
git clone --bare "%remote_old%/!repo!.git"
cd "!repo!.git"
git push --mirror "%remote_new%/!repo!.git"
cd ..
@REM rmdir "!repo!.git"
ENDLOCAL
goto :eof
二、Windows批量切换Git本地仓库地址脚本.bat

使用场景:本地已有源码,不想重新克隆,直接改源码的仓库地址。

使用方法:把此bat和remotes-all.txt文件放在源码的上一级目录双击运行。

@echo off@REM 新的仓库地址
set remote_new=http://gitee.com/git-path
@REM 仓库名称列表:手动创建一个remotes-all.txt文件,多个仓库用换行隔开
set input_file=remotes-all.txtSETLOCAL DisableDelayedExpansion
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ %input_file%"`) do (call :process %%a
)
goto :eof:process
SETLOCAL EnableDelayedExpansion
set "repo=!%1!"
set "repo=!repo:*:=!"REM Check if the directory exists
if not exist "!repo!" (echo Directory "!repo!" does not exist. Skipping...goto :eof
)echo !repo!
cd "!repo!"
git remote set-url origin "%remote_new%/!repo!.git"
cd ..
ENDLOCAL
goto :eof

参考了以下博主的文章,有需要的小伙伴可以,戳↓

流浪_彩虹:git仓库完整迁移的各种方法(代码,分支,提交记录)_git仓库迁移-CSDN博客

http://www.lryc.cn/news/496319.html

相关文章:

  • 【算法刷题指南】优先级队列
  • 使用pymupdf提取PDF文档中的文字和其颜色
  • 贪心算法题
  • Python 3 教程第33篇(MySQL - mysql-connector 驱动)
  • 23种设计模式之外观模式
  • GateWay使用手册
  • MySQL1.0
  • IDEA使用HotSwapHelper进行热部署
  • 简单web项目自定义部署Dockerfile
  • 基础Web安全|SQL注入
  • SpringBoot -拦截器Interceptor、过滤器 Filter 及设置
  • C++小问题
  • avcodec_alloc_context3,avcodec_open2,avcodec_free_context,avcodec_close
  • 强化学习的几个主要方法(策略梯度、PPO、REINFORCE实现等)(下)
  • 计算机网络:IP协议详细讲解
  • 2024信创数据库TOP30之华为Gauss DB
  • 在线家具商城基于 SpringBoot:设计模式与实现方法探究
  • 九、Spring Boot集成Spring Security之授权概述
  • python之Flask入门—路由参数
  • txt地图格式处理
  • 《数据挖掘:概念、模型、方法与算法(第三版)》
  • GitLab CVE-2024-8114 漏洞解决方案
  • request和websocket
  • 一键生成后端服务,MemFire Cloud重新定义开发效率
  • 短视频矩阵的营销策略:批量混剪实现高效传播
  • 朗迪锋亮相2024人因工程与智能系统交互国际会议
  • spring boot3.3.5 logback-spring.xml 配置
  • Proteus8.17下载安装教程
  • 一次Kafka启动失败引出的问题
  • mysql 查询所有的触发器