文章

git push报错:pack exceeds maximum allowed size

git push 仓库报错:

1
2
3
4
5
6
7
8
9
枚举对象中: 302521, 完成.
对象计数中: 100% (302521/302521), 完成.
使用 8 个线程进行压缩
压缩对象中: 100% (182739/182739), 完成.
remote: fatal: pack exceeds maximum allowed size
error: 远程解包失败:index-pack abnormal exit
To git.xxx.com:webrtc/third_party.git
 ! [remote rejected]       rtc-105 -> rtc-105 (unpacker error)
error: 无法推送一些引用到 'https://xxx.com/webrtc/third_party.git'

error: 远程解包失败:index-pack abnormal exit 应该是某些文件超过了git限制。

解决

找了个脚本,非常好使:

REMOTE 改为你要推的远端,我本地仓库对应远端,实际使用改为了upstream,根据需要来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

保存成脚本,放到仓库根目录执行就可以。思想应该就是将仓库分成部分,分批push来解决

参考

  1. https://chegva.com/5658.html
  2. https://zhuanlan.zhihu.com/p/354354365
本文由作者按照 CC BY 4.0 进行授权