remote: fatal: pack exceeds maximum allowed size
问题
# 本地累积了多个提交未推送,计划一次push到位,最后提示
remote: fatal: pack exceeds maximum allowed size
error: remote unpack failed: unpack-objects abnormal exit
现状
$ git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
$ git log -4 --oneline
5623530 (HEAD -> master) 11
02aa878 1
a3e21ec 1
da7ad18 test mix commits to one commit
原因分析
commit过程会将所有需要提交的commit进行打包(pack),该pack存在大小限制,超过后会禁止提交
解决思路,将多个commit分批次提交
解决方案
- 将多个commit,逐次提交(指定commit后,该commit前所有未push的会自动全部push)
# git push <remote_name> <commit_id>:<remote_branch>
$ git push origin da7ad18:master
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (8/8), 825 bytes | 825.00 KiB/s, done.
Total 8 (delta 0), reused 0 (delta 0), pack-reused 0
To ../server_a/
6979203..da7ad18 da7ad18 -> master
- 创建新分支,将需要提交的commit集中cherry-pick到新分支进行提交
$ git branch new_branch origin/master # 创建新分支
branch 'new_branch' set up to track 'origin/master'.
$ git log -3 --oneline # 当前分支
33e7aec (HEAD -> master) 111
5623530 11
02aa878 (origin/master, origin/HEAD, new_branch) 1
$ git log new_branch -3 --oneline # 新创建的分支
02aa878 (origin/master, origin/HEAD, new_branch) 1
a3e21ec 1
da7ad18 test mix commits to one commit
$ git log origin/master -3 --oneline # 远程仓库分支
02aa878 (origin/master, origin/HEAD, new_branch) 1
a3e21ec 1
da7ad18 test mix commits to one commit
# cherry-pick 需求的commit
$ git cherry-pick 5623530
[new_branch 8c09564] 11
Date: Mon Jan 9 18:49:50 2023 +0800
1 file changed, 1 insertion(+)
# push到remote
$ git push origin
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
To ../server_a/
02aa878..8c09564 new_branch -> master
- 不使用cherry-pick,直接创建分支,进行提交
$ git log -3 --oneline # master
b19ab14 (HEAD -> master) 1111
eb0e666 111
8c09564 (origin/master, origin/HEAD, new_branch) 11
$ git checkout -b new_branch2 eb0e666
Switched to a new branch 'new_branch2'
$ git log -3 --oneline # new_branch2
eb0e666 (HEAD -> new_branch2) 111
8c09564 (origin/master, origin/HEAD, new_branch) 11
02aa878 1
$ git push origin new_branch2:master # push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
To ../server_a/
8c09564..eb0e666 new_branch2 -> master
本文来自博客园,作者:flxx,转载请注明原文链接:https://www.cnblogs.com/faithlocus/p/17038321.html