gitlab限制push size的解决办法

在单位的gitlab上新建仓库opengl,然后clone github代码后更新到自己的gitlab上。

这是修改远程仓库的url为自己的仓库url:

git remote set-url --add origin git@git.xxx.com:/opengl.git
git remote set-url --delete origin https://github.com/opengl/opengl.git

然后push master分支:

git push origin master

正常来说,这个操作不会有问题,但是在这个opengl上,碰到了错误:

Compressing objects: 100% (76094/76094), done.
remote: fatal: pack exceeds maximum allowed size
error: remote unpack failed: index-pack abnormal exit

Google搜索,发现stackoverflow有个很好的办法,参考链接:Github remote push pack size

原理:

执行push时,无论大小,git将始终创建一个pack,要解决此问题,需要使用两个(或多个)push:

# 比如:remoteB = origin
git push remoteB <master上的一些先前提交commit id>:master
git push remoteB <上一次提交后的一些先前提交commit id>:master
git push remoteB master

这样分开push会推送更小的包,可以根据需要指定相应的commit id作为不同的分段节点。

在页面的下面有一个脚本,特别适合原始commit特别多的,自己一个一个写git push命令显然不太好操作。

脚本如下:

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

# 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

比如要push master分支,那么先checkout master分支,修改BRANCH=master执行这个脚本,即可成功push整个master分支。

还是在stackoverflow页面回复中,有一段代码,试了下不能工作:

原始代码是:

max=$(git log --oneline|wc -l); \
for i in $(seq  $max -500 1); \
do echo $i; \
  g=$(git log --reverse --oneline --skip $i -n1|perl -alne'print $F[0]'); \
  git push gh $g:refs/heads/master;\
done

把master换成我要push的tag 2.6.0

max=$(git log --oneline|wc -l); \
for i in $(seq  $max -500 1); \
do echo $i; \
  g=$(git log --reverse --oneline --skip $i -n1|perl -alne'print $F[0]'); \
  git push gh $g:refs/heads/2.6.0;\
done

能push,但是中间会出现reject错误:

hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

虽然失败了,这里面的命令还是挺有意思的,这条命令可以最早的commit log在前:

git log --reverse --oneline
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值