You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移超2GB Git仓库时,如何找到大小低于2GB的中间提交?

解决GHEC推送大仓库时的包大小限制问题

问题场景

从GHES迁移3.3GB的仓库至GHEC时,推送触发pack exceeds maximum allowed size (2.00 GiB)错误,需找到合适的历史提交点,将仓库拆分为多次推送,每次推送的pack大小不超过2GB。

方法一:遍历提交并估算bundle大小

通过创建临时bundle文件,逐个验证历史提交对应的仓库打包大小,找到第一个符合2GB限制的提交:

  1. 导出所有提交哈希(按从旧到新排序):
git rev-list --reverse HEAD > commits.txt
  1. 遍历提交并检查bundle大小:
# 2GB对应的字节数为2147483648
MAX_SIZE=2147483648

while read commit; do
  git bundle create temp.bundle $commit
  BUNDLE_SIZE=$(du -b temp.bundle | cut -f1)
  if [ $BUNDLE_SIZE -le $MAX_SIZE ]; then
    echo "符合要求的提交哈希:$commit"
    echo "对应的bundle大小:$(du -h temp.bundle | cut -f1)"
    rm temp.bundle
    break
  fi
  rm temp.bundle
done < commits.txt

找到该提交后,先推送这个提交到GHEC远程仓库:

git push <ghec-remote-name> <commit-hash>:<branch-name>

再推送剩余的提交:

git push <ghec-remote-name> <branch-name>

方法二:定位大文件的首次提交(更高效)

仓库体积过大通常由少数大文件导致,找到这些文件的首次提交,拆分推送:

  1. 找出仓库中体积最大的文件:
git ls-files -s | sort -k 2 -n -r | head -20
  1. 针对每个大文件,查看其首次被提交的历史:
git log --oneline --follow -- path/to/large-file

输出中最底部的提交即为该文件首次被加入的提交。

  1. 拆分推送:
    假设大文件首次提交为X,先推送X的父提交到GHEC:
git push <ghec-remote-name> X^:<branch-name>

再推送从X到当前HEAD的所有提交:

git push <ghec-remote-name> <branch-name>

额外配置建议

推送前可设置Git的HTTP缓冲区大小,避免传输中断:

git config --global http.postBuffer 2147483648

内容的提问来源于stack exchange,提问作者Underoos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 22:32:20