Github更新本地仓库到远程总是失败文件过大,如何解决。

环境:

AI-Sphere-Butler

问题描述:

Github更新本地仓库到远程总是失败文件过大,如何解决。

解决方案:

问题核心在于 历史提交中仍然存在未被 LFS 正确追踪的大文件

终极解决方案 (必须按顺序执行)

第一步:修正路径匹配问题
bash 复制代码
# 进入项目根目录后执行
# 删除现有错误的 .gitattributes
rm .gitattributes

# 重建正确的匹配规则(关键:路径必须与仓库实际结构一致)
echo "wav2lip/face_detection/detection/sfd/s3fd.pth filter=lfs diff=lfs merge=lfs -text" > .gitattributes
echo "wav2lip/models/*.pth filter=lfs diff=lfs merge=lfs -text" >> .gitattributes
第二步:彻底清理 Git 历史中的大文件
bash 复制代码
# 安装必要工具
pip install git-filter-repo

# 强制删除所有提交中的 .pth 文件(包括子目录)
git filter-repo --path-glob '*.pth' --invert-paths --force

# 清理残留引用
git reflog expire --expire=now --all
git gc --prune=now --aggressive
第三步:重新关联 LFS 并提交
bash 复制代码
# 确保 LFS 已安装
git lfs install

# 重新标记 LFS 文件
git lfs track "wav2lip/models/*.pth"
git lfs track "wav2lip/face_detection/detection/sfd/s3fd.pth"

# 强制重新添加所有文件
git add --force .
git commit -m "Rebuild repository with LFS tracking"
第四步:强制推送(彻底覆盖远程)
bash 复制代码
# 再次添加远程仓库
git remote add origin https://github.com/latiaoge/AI-Sphere-Butler.git
# 先推送 LFS 对象
git lfs push origin metahuman-stream --all

# 再强制推送代码库
git push origin metahuman-stream --force


关键注意事项

  1. 路径一致性

    • 确保 .gitattributes 中的路径与仓库实际结构完全匹配,如果 wav2lip 是仓库根目录的子目录,则无需添加 metahuman-stream/ 前缀。
  2. 历史清理验证

    bash 复制代码
    # 检查是否已清除历史大文件
    git log --stat | grep .pth

    如果仍有输出,说明清理不彻底,需要调整 git filter-repo 的路径参数。

  3. GitHub 限制

    • 如果单个 LFS 文件超过 GitHub 的 2GB 存储限制,需自行压缩分卷(但当前文件 204MB 未超限)
  4. 备用方案

    bash 复制代码
    # 如果仍失败,尝试重建仓库
    rm -rf .git
    git init
    git lfs install
    git remote add origin https://github.com/latiaoge/AI-Sphere-Butler.git
    # 重新添加文件并提交

通过以上操作,可确保历史提交中不再包含原生大文件引用,Git LFS 配置与路径完全匹配。

相关推荐
犹若故人归5 小时前
Github/Gitee和Git实践
git·gitee·github
无限进步_10 小时前
【C语言&数据结构】二叉树遍历:从前序构建到中序输出
c语言·开发语言·数据结构·c++·算法·github·visual studio
好想来前端13 小时前
私有化部署 LLM 时,别再用 Nginx 硬扛流式请求了 —— 推荐一个专为 vLLM/TGI 设计的高性能网关
后端·架构·github
charlie11451419115 小时前
用 MkDocs + GitHub Actions 自动化部署项目文档
自动化·github
MemOS17 小时前
MemOS 产品更新|支持全量获取用户记忆,记忆管理与对话体验提升
github
恋猫de小郭17 小时前
Compose Multiplatform 1.10 Interop views 新特性:Overlay 和 Autosizing
android·flutter·macos·kotlin·github·objective-c·cocoa
极客小云19 小时前
【增强版 X-AnyLabeling:支持多模态图像对比标注与 YOLO 标签自动导入】
yolo·目标检测·github·语义分割
CoderJia程序员甲1 天前
GitHub 热榜项目 - 日榜(2026-1-13)
人工智能·ai·大模型·github·ai教程
iuu_star1 天前
项目开源-零基础掌握GitHub大文件上传(Git)
开源·github
wangruofeng1 天前
OpenCode 上手初体验:从安装到基础使用
github·ai编程