【问题标题】:Issues with pushing large files through Git通过 Git 推送大文件的问题
【发布时间】:2013-11-20 10:26:57
【问题描述】:

目前,当我尝试推送到 Git 存储库时,我收到以下错误。

remote: error: GH001: Large files detected.
remote: error: Trace: 7bbfe5c1099cfe679aa3cd1eee13e10a
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File e3384023be667de7529538b11c12ec68.201307290946.sql.gz is 125.37 MB; this exceeds GitHub's file size limit of 100 MB

我已经检查并确保目录中不存在此文件,并已完成git add -u。我们试图修剪分支,但这不起作用,因为它找不到要删除的文件。

【问题讨论】:

  • 通过命令行找不到结果 find --name "*.sql.gz" 也许您的文件位于 phpmyadmin 目录或某个临时目录中?
  • 这似乎也没有找到任何东西。

标签: github


【解决方案1】:

您可能正在推送多个提交,其中一个包含一个大文件,而另一个更新的提交正在删除该文件。

2020-2022:

使用git filter-repo(基于python,为installed first

并使用一些content-based filtering

如果要过滤掉所有大于一定大小的文件,可以使用一定大小的--strip-blobs-bigger-thanKMG 后缀被识别),例如:

git filter-repo --strip-blobs-bigger-than 10M

原始答案,使用obsolete tools like git filter-branch or BFG

在任何情况下,您都可以尝试,如“Fixing the “this exceeds GitHub’s file size limit of 100 MB” error”中所述,过滤器分支(如果您知道您看不到的大文件的名称/路径)

git filter-branch --index-filter 'git rm --cached --ignore-unmatch e3384023be667de7529538b11c12ec68.201307290946.sql.gz' <sha1>..HEAD

或者,如果您不知道但想删除 任何 个大文件(例如 > 90MB),您可以使用 BFG repo cleaner

bfg --strip-blobs-bigger-than 90M  my-repo.git

这将在您的回购历史记录中为您跟踪难以捉摸的大文件并将其删除。
请注意,在那之后您必须执行git push --force,因为最近提交的历史记录将被修改。
如果其他人之前已经克隆了您的 repo,请进行一些沟通以警告他们。

【讨论】:

  • Filter 分支完美运行,为此欢呼!现在全部备份并运行。
  • 您能否澄清一下合并点..HEAD 在您的第一个建议中的含义?我尝试使用它,git说它不知道这是什么意思。
  • @wandadars 来自文章thisprogrammingthing.com/2013/…。我将“合并点”替换为 :您的目的是从该 SHA1(排除)过滤到 HEAD(包含),因此使用要删除的文件的最旧提交,获取其父级,您将拥有 sha1我指的是。
  • 删除`..HEAD`是这对我有用的唯一方法。我得到的错误是bash: sha1: No such file or directory
  • @ThomasMatthew 但是...&lt;sha1&gt; 应该被实际的提交 SHA1 替换。
【解决方案2】:

就我而言,我用这个链接修复了它:

GitHub Help | Working with large files

注意上面写着 giant_file

$ git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch giant_file' \
  --prune-empty --tag-name-filter cat -- --all

$ git commit --amend -CHEAD

$ git push

【讨论】:

    【解决方案3】:

    以下是您可以推送大于 100MB 的对象的步骤:

    1. 安装git-lfs的说明可以在https://git-lfs.github.com/找到

    2. 假设您有大于 100 MB 的 *.jar 文件,然后运行 ​​git lfs track "*.jar。您应该会看到类似

      跟踪“*.jar”

    3. git add .

    4. git push -u origin master

    您应该会看到如下内容:

    Uploading LFS objects:  89% (398/447), 864 MB | 1.8 MB/s
    

    【讨论】:

    • 我一直在努力从以前的 git 中删除多个较大的文件并尝试了多种方法,这是最简单的方法,谢谢!
    【解决方案4】:

    使用filter-branch删除文件

    git filter-branch --tree-filter 'rm -rf your/file/path/task.txt' HEAD
    

    确保您必须添加rm -rf

    然后推送代码

    git push origin master -f
    

    【讨论】:

    • 工作就像一个魅力!谢谢,你是救世主。
    【解决方案5】:

    首先需要解决未暂存的提交。使用git status

    提交这些文件

    git status -s | grep D
    

    提交这些文件

    git status -s | grep M
    

    然后运行这个

    git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path-to-large-file' --prune-empty --tag-name-filter cat -- --all
    

    一旦执行上述命令,将迭代提交历史以找到大文件并将其删除。

    【讨论】:

      【解决方案6】:

      如果您有多个大文件,您需要运行另一个命令:

      git filter-branch --index-filter 'git rm --cached --ignore-unmatch largfile1'
      git filter-branch --index-filter 'git rm --cached --ignore-unmatch largefile2'
      Cannot create a new backup.
      A previous backup already exists in refs/original/
      Force overwriting the backup with -f
      

      你需要跑

      git update-ref -d refs/original/refs/heads/master
      

      然后你可以运行 git filter-branch 命令

      希望对你有帮助

      【讨论】:

      • 也许其他人知道适用于超过一定大小的文件的一般不匹配命令,但 Giant_file 不适用于我的两个文件。我必须将 filter-branch 命令应用于我的两个大文件中的每一个(在两者之间运行 update-ref)。感谢@keminzhou 的建议,我能够解决我的大文件双重提交问题。
      猜你喜欢
      • 2019-04-05
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 2020-03-20
      • 1970-01-01
      • 2013-07-22
      • 2022-01-28
      • 1970-01-01
      相关资源
      最近更新 更多