github push文件过大如何解决?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hy971216/article/details/83032339

git push 文件大于100M导致push失败。

首先有一点要注意:GitHub建议上传的文件大小要求是不超过50M,允许的大小是不超过100M,如果你实在有需要,可以使用git lfs大存储,网址:https://git-lfs.github.com

今天我在push本地仓库到GitHub之前往仓库里就加了一个100多M的大文件,之后依次执行了

git add .
git commit -m "add new file"
git push -u origin master

然而push时出现了如下报错

remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: f733e04b6245057887da1dc0d0628aee
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File XXXXXX.pdf is 145.92 MB; this exceeds GitHub's file size limit of 100.00 MB

傻傻的我当时想到的就是先删除本地仓库中的这个大文件,然后重新git add , git commit , git push.然而push时还是报了同样的错误。我想应该是我的操作只是删除了本地仓库里的大文件,但是却并没有修改掉git 之前的提交记录,所以push的时候依然还是会显示你push了大文件。我之后便按照git 的官方help文档去处理,
Removing files from a repository’s history
但是在按照这个流程操作时又出现了问题,我执行git rm --cached命令时出现了如下错误

fatal: pathspec 'XXXX' did not match any files

一开始我想应该是由于我已经移除了本地文件才会出现这样找不到文件的错误,于是我又先将原文件拷贝进之前的文件夹,然后继续执行rm命令,结果仍然报了上述操作,自然后面的git commit --amend -CHEAD 和 git push 也就无法进行了。
此路不通,我又换了个法子,也就是用reset恢复命令。
首先执行:git log 查看你之前的提交日志,然后执行git reset XXX,恢复到你没有添加大文件的那次commit记录。之后再按命令去git push 即可。

commit 184512f9eb2c16d1ade200d65ffb6f55f89f4c77 (HEAD -> master)
Author: Your Name <[email protected]>
Date:   Fri Oct 12 19:09:49 2018 +0800

    commit all

commit 89b6883057297af12c18ec5c57d87d8115fa6a9b
Author: Your Name <[email protected]>
Date:   Fri Oct 12 18:41:42 2018 +0800

    add file

commit c996cf99382e8b3fdbd95d4cbc230910c5f9be71
Author: Your Name <[email protected]>
Date:   Fri Oct 12 18:19:06 2018 +0800

    add file

commit f09a91e38682e25c3d75e82e64d9d04cb0b68723 (origin/master, origin/HEAD)
Author: XXXXX <[email protected]>
Date:   Fri Oct 12 14:02:10 2018 +0800


还有一种方法是利用checkout处理分支,但这个我还不大会。

猜你喜欢

转载自blog.csdn.net/hy971216/article/details/83032339
今日推荐