迁移一个或多个完整的git仓库

本文详细介绍了如何将Git仓库从一个位置迁移到另一个位置,包括所有分支、标签、历史记录和日志的完整迁移过程。提供了手动迁移和批量迁移的方法,适合需要进行仓库迁移的开发者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

迁移仓库:包括所有分支,tag等…

一、迁移一个Git仓库
把一个git仓库迁移到另外一个git仓库,含所有的分支,标签,历史记录,日志

git clone --mirror <URL to my OLD repo location>
cd <New directory where your OLD repo was cloned>
git remote set-url origin <URL to my NEW repo location>
git push -f origin

二、批量迁移仓库
move.sh文件

#!/bin/bash

filename=$1
IFS=$'\n\n'

for line in `cat $filename`
do
  # echo $line
  OLD_IFS="$IFS"
  IFS=";"
  array=($line)
  IFS="$OLD_IFS"

  old_origin=${array[0]}
  new_origin=${array[1]}
  echo "old origin: ${old_origin}"
  echo "new origin: ${new_origin}"
  mkdir workdir
  sup_path=`pwd`
  cd workdir
  path=`pwd`
  echo "开始clone项目..."
  git clone --mirror $old_origin
  echo "clone项目完毕."

  for dir in `ls .`
  do
  if [ -d $dir ]
  then
  echo "项目目录: $dir"
  cd $dir
  echo "修改项目origin url..."
  git remote set-url origin $new_origin
  echo "开始推送新仓库..."
  git push -f origin
  echo "推送完毕."
  fi
  done
  rm -rf $path
  cd $sup_path
  echo "done"
done

data.txt文件
.txt文件里面:每一行是一条记录
旧的git仓库地址,分号,新的仓库地址

<旧的git仓库地址>;<新的git仓库地址>
<旧的git仓库地址>;<新的git仓库地址>
<旧的git仓库地址>;<新的git仓库地址>

执行命令

bash move.sh data.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值