0


gitlab限制push size的解决办法

在单位的gitlab上新建仓库

opengl

,然后clone github代码后更新到自己的gitlab上。

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

git remote set-url --add origin [email protected]:/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 = origingit 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 necessaryREMOTE=origin
BRANCH=$(git rev-parse --abbrev-ref HEAD)BATCH_SIZE=500# check if the branch exists on the remoteifgit show-ref --quiet--verify refs/remotes/$REMOTE/$BRANCH;then# if so, only push the commits that are not on the remote alreadyrange=$REMOTE/$BRANCH..HEAD
else# else push all the commitsrange=HEAD
fi# count the number of commits to pushn=$(git log --first-parent --format=format:x $range |wc-l)# push each batchforiin$(seq $n -$BATCH_SIZE 1);do# get the hash of the commit to pushh=$(git log --first-parent --reverse--format=format:%H --skip $i -n1)echo"Pushing $h..."git push $REMOTE${h}:refs/heads/$BRANCHdone# push the final partial batchgit push $REMOTE HEAD:refs/heads/$BRANCH

比如要push master分支,那么先

checkout master

分支,修改

BRANCH=master

执行这个脚本,即可成功push整个master分支。

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

原始代码是:

max=$(git log --oneline|wc-l);\foriin$(seq  $max -5001);\doecho$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);\foriin$(seq  $max -5001);\doecho$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
标签: gitlab git github

本文转载自: https://blog.csdn.net/hongszh/article/details/128336040
版权归原作者 HUI的技术笔记 所有, 如有侵权,请联系我们删除。

“gitlab限制push size的解决办法”的评论:

还没有评论