快轉到主要內容

Github 檔案太大無法推送!?安裝「Git-LFS」馬上解決!

·875 字· loading · loading ·
目錄

使用 git push 推送檔案到 Github 上時,被告知檔案太大無法推送!?馬上教你怎麼解決!


報錯
#

當你嘗試使用 git push 推送超過100 MB的檔案時,沒意外就會收到這樣的錯誤。
這是因為 Github 一個檔案最大上傳限制就是100 MB。(ps. 分開上傳可以,但不能同個檔案 100 MB)

1$ remote: error: GH001: Large files detected.
2$ remote: error: Trace: xxxxxxxxxxxxxxxxxxxx
3$ remote: error: See http://git.io/iEPt8g for more information.
4$ remote: error: File xxxxxxxxxxxxx is 101.00 MB; this exceeds GitHub's file size limit of 100 MB

安裝 Git-LFS 解決!
#

為此 Github 也提供解決方法 - 「Large File Storage」。

Debian and Ubuntu
#

1curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
2sudo apt-get install git-lfs
3git lfs install

Mac OSX
#

1brew update
2brew install git-lfs
3git lfs install

RHEL/CentOS
#

Step.1 安裝 git >= 1.8.2
#

如果你的版本是 RHEL/CentOS 57 (而不是 6)的話:
a. 可以按這裡安裝 (如果是 CentOS 那麼你只需要執行 sudo yum install epel-release)
b. sudo yum install git

如果你的版本是 RHEL/CentOS 6
a. curl -s https://setup.ius.io/ | sudo bash
b. sudo yum install git2u

如果你想,你也可以自己建構原始碼。您將需要手動下載 Git-lfs rpm 並進行安裝 rpm -i --nodeps git-lfs*.rpm

Step.2 安裝 git-lfs
#

1curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
2sudo yum install git-lfs
3git lfs install

Windows
#

Step.1 下載安裝檔
#

可以從 https://github.com/git-lfs/git-lfs/releases 選擇你要的版本進行下載。

Step.2 執行安裝檔
#

Step.3 在 CMD 或者 Git-Bash 執行 git lfs install
#


開始使用
#

在下 git 指令時,你只需要將追蹤大檔案(超過 100 MB)的指令 git add 改成 git lfs track
舉例來說,如果要追蹤副檔名為.psd的大檔案,那請使用

1git lfs track "*.psd"

不是 git add "*.psd"
並且確保檔案 .gitattributes 有被追蹤。 (這是用來告知 github 此為大型檔案的文件)

1git add .gitattributes

之後的指令照舊, git add > git commit > git push
回到 Github Repository 就可以發現成功被推送了。


如何取消 LFS ?
#

  • 刪除單個檔案
    如果你是要刪除單個檔案,那麼就需要麻煩點到「.gitattributes」這個檔案中去刪除單筆資料,使 Github 知道該檔案不用再被 LFS 給追蹤。
  • 移除全部 (不使用 LFS 了)
    你需要使用指令「git lfs uninstall」,如果你是較舊的版本則是使用指令「git lfs uninit」來刪除該 Repository 中的 LFS 。
    另外也請確保檔案「.gitattributes」不再被追蹤。(建議如果不需要,請直接下 git rm .gitattributes 刪除它)

範例:

1git lfs uninstall
2git rm .gitattributes
3git add .
4git commit "Uninstall LFS"
5git push origin main

參考資料
#

Alpaca
作者
Alpaca
No one can stop my feet.

相關文章