在单位的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