git提交超过文件限制的解决办法

git提交超过文件限制的解决办法

问题

1
2
3
4
5
6
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File new-nsita/bitmap/bitmap.pdf is 189.85 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 https://github.com/wanqqq29/Daily-HTML.git
! [remote rejected] xxx -> xxx (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/wanqqq29/Daily-HTML.git'

报错信息中第三行提示文件太大

解决方法

  1. 查看是哪个文件超过限制
    • 第二行remote: error: File new-nsita/bitmap/bitmap.pdf is 189.85 MB; this exceeds GitHub's file size limit of 100.00 MB说明是bitmap.pdf这个文件太大,超过了100M的限制。所以我们就要处理这个文件了
  2. 重写commit,删除大文件
    • git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch new-nsita/bitmap/bitmap.pdf' --prune-empty --tag-name-filter cat -- --all注意将new-nsita/bitmap/bitmap.pdf替换成你的路径与文件
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
       WARNING: git-filter-branch has a glut of gotchas generating mangled history
      rewrites. Hit Ctrl-C before proceeding to abort, then use an
      alternative filtering tool such as 'git filter-repo'
      (https://github.com/newren/git-filter-repo/) instead. See the
      filter-branch manual page for more details; to squelch this warning,
      set FILTER_BRANCH_SQUELCH_WARNING=1.
      Proceeding with filter-branch...
      Rewrite 2621a6906cd6cf828ccf659622c8959c98e6eaab (3/5) (1 seconds passed, remaining 0 predicted) rm 'new-nsita/bitmap/bitmap.pdf'
      WARNING: Ref 'refs/heads/master' is unchanged
      Ref 'refs/heads/xxx' was rewritten
      WARNING: Ref 'refs/remotes/origin/master' is unchanged
      WARNING: Ref 'refs/stash' is unchanged
      看到第8行提示重写 说明成功
    不要忘了检查本地大文件还在不
  3. 强制推送修改后的repo
    • git push origin xxx --force xxx是你当前的分支名
    • 可以看到成功推送

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!