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

无法将GitLab代码(含提交历史及大文件)迁移至GitHub求解决方案

GitLab代码带提交历史迁移GitHub失败(含大文件)

我尝试将GitLab中的代码连同提交历史一起迁移至GitHub,但操作失败;不过不带提交历史的话可以正常完成迁移。具体错误日志如下:

$ git push github master
Uploading LFS objects: 100% (2/2), 265 MB | 23 MB/s, done.
Enumerating objects: 49, done.
Counting objects: 100% (49/49), done.
Delta compression using up to 4 threads
Compressing objects: 100% (34/34), done.
Writing objects: 100% (49/49), 278.93 MiB | 38.63 MiB/s, done.
Total 49 (delta 13), reused 42 (delta 11), pack-reused 0
remote: Resolving deltas: 100% (13/13), done.
remote: error: Trace: df012bdf3866620fba543b---------------------------------
remote: error: See https://gh.io/lfs for more information.
remote: error: File Manual.docx is 142.02 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File jar/abcbit.jar is 111.12 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To <<github_repository_url>>
![remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'github_repository_url'

解决办法

方案1:用Git LFS托管大文件(保留完整提交历史)

  1. 在本地仓库初始化Git LFS:
    git lfs install
    
  2. 标记需要用LFS托管的大文件:
    git lfs track "Manual.docx"
    git lfs track "jar/abcbit.jar"
    
  3. 提交LFS配置文件到仓库:
    git add .gitattributes
    git commit -m "用Git LFS托管大文件"
    
  4. 重新推送代码至GitHub:
    git push github master
    

方案2:彻底移除提交历史中的大文件(永久缩减仓库体积)

如果不想使用LFS,可通过改写提交历史,把大文件从所有历史记录中删除:

  1. 使用git filter-repo工具移除目标大文件(该工具比传统的filter-branch更安全高效):
    git filter-repo --path Manual.docx --invert-paths
    git filter-repo --path jar/abcbit.jar --invert-paths
    
  2. 强制推送改写后的仓库到GitHub:
    git push github master --force
    

注意:改写提交历史后,所有协作开发者需要重新克隆仓库,避免出现历史冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 20:25:21