git上傳大檔案!git push 報錯 ! [remote rejected] main -> main (pre-receive hook declined) error_ failed to push some refs to 'xxx

想你时风起發表於2024-04-07

前言

今天在用git push專案的時候,出現了一個報錯,記錄一下解決方案,以後報同樣的錯誤可以回來看。

錯誤資訊

下面是git push的詳細報錯資訊:

20866@DESKTOP-7R0VL04 MINGW64 /d/AllProjects/JupyterProjects (main)
$ git push origin main
Enumerating objects: 152, done.
Counting objects: 100% (152/152), done.
Delta compression using up to 8 threads
Compressing objects: 100% (147/147), done.
Writing objects: 100% (152/152), 1.45 GiB | 3.57 MiB/s, done.
Total 152 (delta 19), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (19/19), done.
remote: error: Trace: 33c674f670a5be28e672de71fddd6350a7b7bb12f12e9ee5727cb7193071e41b
remote: error: See https://gh.io/lfs for more information.
remote: error: File Recommender Sysytem/music_data.tsv is 2412.03 MB; this exceeds GitHub's file size limit of 100.0
remote: error: File Recommender Sysytem/track_metadata.db is 711.61 MB; this exceeds GitHub's file size limit of 100
remote: error: File Recommender Sysytem/train_triplets.txt is 2862.61 MB; this exceeds GitHub's file size limit of 1
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/wephiles/jupyterProjects.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/wephiles/jupyterProjects.git'

如圖所示:
image

檢視報錯資訊:

錯誤資訊提示我們,出錯的原因是因為單個檔案大小超出了github的最大檔案大小100M;

remote: error: File Recommender Sysytem/music_data.tsv is 2412.03 MB; this exceeds GitHub's file size limit of 100.0

解決方法

根據報錯資訊的提示,git提示我們去https://git-lfs.github.com檢視傳輸大檔案的方法。

remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com

我們開啟這個網址,看到下面這樣的頁面:

image

檔案詳細介紹瞭如何傳輸大檔案:
image

  • 首先安裝下載並初始化:git lfs install,如果你以前沒用過這個擴充套件,那麼你需要使用這個命令;如果你已經用過了,你可以跳過這個步驟;

  • 使用命令 git lfs track "這裡面寫你的檔名稱",如果有多個大檔案,把每個檔案都是用同樣的方法操作就可;
    image

  • 使用命令 git add .gitattributes
    image

  • 接下來就是常用的步驟,將檔案push上去即可

    git add "這裡寫你的檔名稱"
    git commit -m "這裡寫你的提交資訊"
    git push origin main
    

提交完成後就可以愉快地傳大檔案到github了:

image

我的提交又報錯了,根據提示,檔案的大小要小於等於2GB,那隻能把這個大檔案刪除了,在上傳剩下的檔案了。
image

我們刪除兩個大檔案後,成功push!
image

相關文章