gitlab 仓库迁移,以及解决remote: fatal: pack exceeds maximum allowed size

文章介绍了三种方法来迁移Git仓库,当遇到提交或标签过大导致失败的问题时,可以尝试使用分批提交的脚本或者使用镜像推送。方法一通过修改远程仓库名并推送全部内容,但可能会遇到大小限制错误。方法二提供了一个脚本,分批推送commit以避免一次性推送过多。方法三是通过镜像克隆后再推送,适用于整个仓库的迁移。

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

背景:是需要新建一个仓库,把老的仓库里面的git提交啥的都迁移过来。但是呢,总是失败,提醒大致意思就是提交的commit和tag太大了不行。

目录

方法一:命令迁移

方法二:脚本迁移

方法三:镜像


方法一:命令迁移

基本方法:

cd existing_repo
git remote rename origin old-origin
git remote add origin git@host/*.git
git push -u origin --all
git push -u origin --tags

但是过程中会报错: 

提示

remote: fatal: pack exceeds maximum allowed size
error: remote unpack failed: unpack-objects abnormal exit

方法二:脚本迁移

解决办法呢,就是我们不一下把所有的commit提交,改为分步骤提交就可以了。

前提是也设置好上面的命令了

cd existing_repo
git remote rename origin old-origin
git remote add origin git@host/*.git

提交commit改为下面的脚本就可以了

#!/bin/bash


# Adjust the following variables as necessary
REMOTE=origin
BRANCH=$(git rev-parse --abbrev-ref HEAD)
BATCH_SIZE=100

# check if the branch exists on the remote
if git show-ref --quiet --verify refs/remotes/$REMOTE/$BRANCH; then
    # if so, only push the commits that are not on the remote already
    range=$REMOTE/$BRANCH..HEAD
else
    # else push all the commits
    range=HEAD
fi
# count the number of commits to push
n=$(git log --first-parent --format=format:x $range | wc -l)

# push each batch
for i in $(seq $n -$BATCH_SIZE 1); do
    # get the hash of the commit to push
    h=$(git log --first-parent --reverse --format=format:%H --skip $i -n1)
    echo "Pushing $h..."
    git push $REMOTE ${h}:refs/heads/$BRANCH
done
# push the final partial batch
git push $REMOTE HEAD:refs/heads/$BRANCH

方法三:镜像

可以将源端仓库,镜像克隆到本地,再镜像推送到目的端。

git clone --mirror git@host:group1/repo.git
git push --mirror git@host:group2/repo.git
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值