彻底解决 git push 的【pack exceeds maximum allowed size】

这篇具有很好参考价值的文章主要介绍了彻底解决 git push 的【pack exceeds maximum allowed size】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

其实一个 Git 远程仓库除了限制单文件大小和仓库大小之外,还有一个单次推送的大小。比如 Github 它的单次推送大小大约是 5GB,如果超出就会报这个错误。

一些历史久远的仓库,虽然单文件大小和仓库大小没有超出限制,但是如果你一次性pull再push,就会超出这个限制。

解决办法很简单,就是按照提交的顺序一个一个 push。为此我专门写了个 Python 脚本,来实现自动化。

核心代码:

# 逐个推送提交
def git_push_per_commit(args):
    dir = args.dir
    work_branch = args.branch
    remote = args.remote
    print(f'branch: {work_branch}, remote: {remote}')
    if not is_git_repo(dir):
        print('请提供 GIT 本地仓库')
        return
    # 检查分支是否存在
    branches = get_all_branches(dir)
    if work_branch not in branches:
        print(f'分支 {work_branch} 不存在')
        return
    # 如果远程仓库名为地址,创建别名
    if remote.startswith('https://') or \
        remote.startswith('git@'):
            url, remote = remote, uuid.uuid4().hex
            subp.Popen(
                ['git', 'remote', 'add', remote, url],
                shell=True, cwd=dir,
            ).communicate()
    # 检查远程库是否存在
    remotes = get_remote_names(dir)
    if remote not in remotes:
        print(f'远程仓库 {remote} 不存在')
        return
            
    # 检查远程库是否有该分支
    subp.Popen(
        ['git', 'remote', 'update', remote],
        shell=True, cwd=dir,
    ).communicate()
    branches = get_all_branches(dir)
    remote_exi =  f'remotes/{remote}/{work_branch}' in branches
    if not remote_exi:
        # 如果远程分支不存在,推送本地分支所有提交
        cids = get_branch_cids(dir, work_branch)
    else:
        # 拉取远程分支,并重命名
        remote_branch = f'{remote}-{work_branch}-{uuid.uuid4().hex}'
        subp.Popen(
            ['git', 'fetch', remote, f'{work_branch}:{remote_branch}'],
            shell=True, cwd=dir,
        ).communicate()
        # 查看远程库是否有新提交
        cids = get_branch_cids(dir, remote_branch, '^' + work_branch)
        if cids:
            print('远程仓库有新的提交,需要手动 git pull')
            print('\n'.join(cids))
            return
        # 查看本地库的新提交
        cids = get_branch_cids(dir, work_branch, '^' + remote_branch)
    for cid in cids[::-1]:
        cid_branch = 'cid-' + cid
        cmds = [
            # 切换分支
            ['git', 'checkout', cid, '-f'], 
            ['git', 'branch', cid_branch],
            # 提交改动
            ['git', 'push', remote, f'{cid_branch}:{work_branch}'],
        ]
        for cmd in cmds:
            subp.Popen(cmd, shell=True, cwd=dir).communicate()

args是数据对象,打包所有所需参数,包括dir——本地仓库路径,remote远程仓库别名或者地址,branch要推送的本地分支名称(假定远程分支名称和本地一样,不一样的你本地重命名一下就好了)。

代码做必要的检查之后,直接获取提交 ID 然后按时间顺序 push。如果远程仓库已经 push 了一些东西,那就把 ID 做个差。

其它依赖函数都在 apachecn/BookerPubTool 里面,就不贴出来了。各位也可以封装 GitPython 来实现。

一键调用:文章来源地址https://www.toymoban.com/news/detail-619242.html

pip install BookerPubTool
pub-tool <dir> [-b <branch=master>] [-r <remote=origin>]

到了这里,关于彻底解决 git push 的【pack exceeds maximum allowed size】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【异常】The field file exceeds its maximum permitted size of 1048576 bytes.

    本项目是个Springboot 项目,功能是要做一个文件上传,在测试时发现报错,上传的是一个 word 文件,大小是 1.25MB,报错内容如下: Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes. 详细报错内容如下图

    2024年03月15日
    浏览(31)
  • uni-app、小程序项目,在分包后访问地址无法跳转,出现异常:RangeError: Maximum call stack size exceeded

    使用uni-app开发小程序,由于微信小程序对代码包体积有大小限制,故分包处理,同时也做了分包预加载 分包后,一个点击事件,同一个跳转地址,在浏览器下正常跳转,在微信开发者工具内出现如下报错 出现异常: RangeError: Maximum call stack size exceeded 如图: 原因:很有可能

    2024年02月12日
    浏览(28)
  • 彻底解决 git push --set-upstream origin 问题

    当我们在使用 Git 切换新分支时,每次推送代码时都需要使用 git push --set-upstream origin branch 将本地分支与远程分支关联,否则 Git 就不知道我们想要将代码推送到哪个远程分支。虽然这样做可以保证推送的准确性,但是在切换分支时频繁使用该命令会显得繁琐和不便。 为了避

    2024年02月11日
    浏览(45)
  • oracle sqlldr 数据导入时报错:Field in data file exceeds maximum length完美解决

    使用oracle sqlldr进行数据导入时报Field in data file exceeds maximum length错误的解决办法: 一种是数据字段确实比数据库中的字段要长,这中错误需要调整数据库字段的长度,一种是减小字段的长度。 第二种是因为要入库的字段问题(中文问题),这种问题在control文件中添加字符类型表示

    2024年02月16日
    浏览(36)
  • [git push]remote: error: File: MB, exceeds 100.00 MB.git push提示文件大于100m处理方法与git删除缓存文件

    使用git push将本地项目push到gitee时,发生错误报告,如下图所示: 标红的error显示: error: File: f8ca2c1b4c347904a4b088d145b55e9c2b595f80 102.62 MB, exceeds 100.00 MB. 可知gitee超过100MB的文件无法上传,此时如果在项目中删除此文件,重新使用 git add . 、 git commit -m \\\"XXX\\\" 的方式,会导致文件依然

    2024年03月25日
    浏览(37)
  • gitlab限制push size的解决办法

    在单位的gitlab上新建仓库 opengl ,然后clone github代码后更新到自己的gitlab上。 这是修改远程仓库的url为自己的仓库url: 然后push master分支: 正常来说,这个操作不会有问题,但是在这个opengl上,碰到了错误: Google搜索,发现stackoverflow有个很好的办法,参考链接:Github remote

    2024年02月05日
    浏览(36)
  • 【Git】大问题大问题~remote: error: File: MB, exceeds 100.00 MB.git push提示我文件大于100m处理方法

    今天,在将本地的文档提交到gitee仓库时,突然爆了个大错误!什么100MB,在网上一通乱找,总结如下: 其实根据报错原因提示: Gitee免费用户单个文件最大100M,因此只能上传小于100M文件。 解决方案 查看哪个文件超过了100M 有可能错误直接爆出是哪个文件,也有可能只是爆

    2024年02月13日
    浏览(31)
  • git push错误:You are not allowed to force push code to a protected branch on this project

            本地使用 git push --force origin 命令强制推送时,出现 “You are not allowed to force push code to a protected branch on this project”错误,意为该分支为受保护的,不允许这类操作,可以通过git管理后台关闭该项目分支的保护状态处理。 使用管理员账号进入git中的项目设计,setting

    2024年02月11日
    浏览(58)
  • 【已解决】github上传大文件:this exceeds GitHub‘s file size limit of 100.00 MB

    通过 git 推送更新到远程仓库时报错 remote: error: File \\\"path_of_your_large_file\\\" is 243.28 MB; this exceeds GitHub\\\'s file size limit of 100.00 MB 导致这个错误的本质原因是 GitHub限制上传文件大小在100 MB以内 ,这是为了确保系统的稳定性和可用性,因为较大的文件可能会导致服务器处理时间变慢,

    2024年02月05日
    浏览(35)
  • python报错ValueError: zero-size array to reduction operation maximum which has no identity,情况之一分析与解决

    在boston房价数据预测练习项目中,发现报错如下: ValueError: zero-size array to reduction operation maximum which has no identity 此报错所对应行为 于是网上查找对应错误解决方法,有的博主的numpy数组处array.max(axis=0)、array.min(axis=0),的确有数组为0的情况,采纳其建议加入assert array.size !=

    2024年02月08日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包