Git 推送代码时可能遇到两类常见错误:RPC failed; HTTP 500 curl 22(缓冲区不足)和文件超过仓库大小限制(如 GitHub 100MB)。本文针对这两类问题提供完整解决方案。第一类错误原因为默认缓冲区大小仅 1MB,传输图片等大文件时触发,解决方法为 git config --global http.postBuffer 524288000(设置为 500MB)。第二类错误原因为项目中存在超过 100MB 的大文件,解决方案为安装 Git LFS、配置 .gitattributes 文件跟踪大文件类型(如 *.zip、*.mp4、*.psd),并通过 git lfs track 命令将大文件迁移到 LFS 管理。
本文适用于遇到 Git 推送失败的开发人员。
textgit -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/master:master Enumerating objects: 17, done. Counting objects: 5% (1/17) Counting objects: 11% (2/17) ... Writing objects: 68% (11/16) error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500 send-pack: unexpected disconnect while reading sideband packet Writing objects: 75% (12/16) Writing objects: 100% (16/16) Writing objects: 100% (16/16), 1.73 MiB | 4.47 MiB/s, done. Total 16 (delta 0), reused 0 (delta 0), pack-reused 0 fatal: the remote end hung up unexpectedly
text缓冲区大小默认为 1MB,当传一些比如图片时会报此错。所以要确保服务器的 Git 配置允许足够大的数据传输。
shell# 设置大小为500M
git config --global http.postBuffer 524288000
textThe push operation includes a file which exceeds GitHub's file size restriction of 100MB. Please remove the file from history and try again. Files that exceed the limit
text项目中存在超过100MB的大文件
shell# 安装 Git LFS
git lfs install
# 在项目根目录下创建或编辑 .gitattributes 文件,指定哪些文件类型应该用 LFS 管理
touch .gitattributes
# 规则语法
pattern filter=lfs diff=lfs merge=lfs -text
# Demo
# 跟踪所有 ZIP 文件
*.zip filter=lfs diff=lfs merge=lfs -text
# 跟踪所有视频文件
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text
# 跟踪所有 Photoshop 文件
*.psd filter=lfs diff=lfs merge=lfs -text
# 跟踪 assets 目录下所有文件
assets/** filter=lfs diff=lfs merge=lfs -text
# 跟踪特定大文件
/path/to/large/file.data filter=lfs diff=lfs merge=lfs -text
# A:提交并推送更改
git add .gitattributes
git commit -m "配置 Git LFS 跟踪大文件"
git push origin main
# B:如果仓库中已有大文件,需要明确跟踪它们
# 跟踪特定类型
git lfs track "*.psd"
# 或者跟踪特定文件
git lfs track "path/to/large/file.data"
# 然后重新添加这些文件
git add path/to/large/file.data
git commit -m "将大文件迁移到 LFS"
git push origin main
# 检查哪些文件被 LFS 跟踪
git lfs ls-files


本文作者:Odboy
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC 4.0 BY-SA 许可协议。转载请注明出处!