背景:是需要新建一个仓库,把老的仓库里面的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