git 超出 Github 远程推送包大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15125862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:36:38  来源:igfitidea点击:

Github remote push pack size exceeded

gitgithubgit-push

提问by seekinganswers

I am new to Git and have a fairly large project that I want to push to a remote repo (Repo B) on Github. The original project was on Github as well but from a different repo (Repo A). I have to make some changes to files from Repo A before I can setup the project up on Repo B. I have setup the remotes, ssh keys etc. and I run into an issue when pushing the codebase to Repo B.

我是 Git 的新手,并且有一个相当大的项目,我想将其推送到 Github 上的远程存储库(存储库 B)。最初的项目也在 Github 上,但来自不同的 repo (Repo A)。我必须对 Repo A 中的文件进行一些更改,然后才能在 Repo B 上设置项目。我已经设置了遥控器、ssh 密钥等,但在将代码库推送到 Repo B 时遇到了问题。

I get the following error all the time:

我一直收到以下错误:

$ git push <remote_repo_name> master
Enter passphrase for key '/c/ssh/.ssh/id_rsa':
Counting objects: 146106, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (35519/35519), done.
fatal: pack exceeds maximum allowed size00 GiB | 154 KiB/s
fatal: sha1 file '<stdout>' write error: Invalid arguments
error: failed to push some refs to '[email protected]:<repo>.git

I changed the following settings in my local gitconfig

我在本地 gitconfig 中更改了以下设置

git config pack.packSizeLimit 1g
git config pack.windowMemory 1g

... and ran git gc (which I see reorganized the packs so that each pack stayed within the packsize of 1GB). This did not work and I get the error seen above.

...并运行 git gc (我看到它重新组织了包,使每个包保持在 1GB 的包大小内)。这不起作用,我收到了上面看到的错误。

I tried to lower the size of each pack as well ....

我也试图降低每个包的大小......

git config pack.packSizeLimit 500m
git config pack.windowMemory 500m

... and ran git gc (which I see reorganized the packs so that each pack stayed within the packsize of 500MB). This did not work either and I ran into the same error.

...并运行 git gc (我看到它重新组织了包,使每个包保持在 500MB 的包大小内)。这也不起作用,我遇到了同样的错误。

I am not sure of what Github's default packsize limits are (if any). The account is a micro account if that matters.

我不确定 Github 的默认包大小限制是什么(如果有的话)。如果这很重要,该帐户是一个微型帐户。

回答by onionjake

The packsize limit does not affect git protocol commands (your push).

packsize 限制不会影响 git 协议命令(您的推送)。

From git-configunder pack.packSizeLimit:

git-configpack.packSizeLimit

The maximum size of a pack. This setting only affects packing to a file when repacking, i.e. the git:// protocol is unaffected.

一个包的最大尺寸。此设置仅影响重新打包时打包到文件,即 git:// 协议不受影响

When executing a push git will always create exactly one pack no matter the size!

执行推送时,无论大小如何,git 都将始终创建一包!

To fix this use two (or more) pushes:

要解决此问题,请使用两次(或多次)推送:

git push remoteB <some previous commit on master>:master
...
git push remoteB <some previous commit after the last one>:master
git push remoteB master

These pushes will all have smaller packs and will succeed.

这些推送都会有较小的包并且会成功。

回答by Daniel Harding

As onionjake noted in his answer, the pack.packSizeLimitsetting does not affect pushes. As he suggested, this can often be addressed by using multiple pushes with fewer commits each. rurban posted a comment on how to automatically push chunks of 500 commits. Following is a modified version of his comment, generalized to work correctly regardless of whether the branch on the remote does not exist or exists and contains some of the commits already. I also added the --first-parentargument to the git logcalls to prevent errors when the repository contains multiple root commits. I also made some tweaks to improve effiency, and added an additional call to git pushto push the final (partial) batch of commits:

正如 onionjake 在他的回答中所指出的,该pack.packSizeLimit设置不会影响 pushes。正如他所建议的,这通常可以通过使用多次推送来解决,每次推送的次数较少。rurban 发表了关于如何自动推送 500 个提交块的评论。以下是他的评论的修改版本,无论远程分支是不存在还是存在并且已经包含一些提交,都可以正常工作。当存储库包含多个根提交时,我还在调用中添加了--first-parent参数以git log防止错误。我还进行了一些调整以提高效率,并添加了一个额外的调用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