使用Git LFS上傳大文件到GitHub教程,以及可能會遇到的坑(使用了Git LFS卻依然傳不上超過100M的文件;framework庫如何添加等)

什麼是Git LFS?

Git LFS(Large File Storage) 是 Github 開發的一個 Git 的擴展,用於實現 Git 對大文件的支持

簡單的說,就是如果你想傳超過100M的二進制文件到GitHub,你就要用Git LFS!

安裝Git LFS

首先確保電腦已經安裝了Git並且版本不低於1.8.5

下面爲不同平臺的安裝方法:

Linux

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

Mac

 (

  1. 安裝HomeBrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. brew install git-lfs
  3. git lfs install

本人爲mac版本,在安裝時候發生了權限錯誤問題,提示“

fatal: cannot copy '/usr/local/git/share/git-core/templates/hooks/pre-receive.sample' to '/usr/local/Homebrew/.git/hooks/pre-receive.sample': Permission denied

 ”解決辦法:https://stackoverflow.com/questions/40592463/homebrew-install-fails-while-copying-files

 

Windows

  1. 下載安裝 windows installer
  2. 運行 windows installer
  3. 在命令行執行 git lfs install

可以通過命令“git lfs version”來查看git lfs是否安裝完成

如何使用Git LFS

下面開始添加大文件到git lfs

所有的步驟都完成了

可能會遇到的問題

1,(使用了Git LFS卻依然傳不上超過100M的文件)

進行到上面第五步git push之後依然提示,文件超過100M,上傳失敗之類的錯誤信息,如下

 

  1. 如果有大文件"xxx/aaa",xxx爲你啓動終端的相對路徑,aaa是超過100M的大文件
  2. 輸入命令git lfs track "xxx/aaa"---添加aaa文件,git lfs會在工程目錄下生成一個gitattributes
  3. 輸入命令git add .
  4. 輸入命令git commit -m "add big file aaa to the github"
  5. 輸入命令git push

wodeMacBook-Pro:xxx$ git push origin master

Uploading LFS objects: 100% (1/1), 137 MB | 0 B/s, done                         

Counting objects: 111, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (110/110), done.

Writing objects: 100% (111/111), 56.71 MiB | 174.00 KiB/s, done.

Total 111 (delta 21), reused 0 (delta 0)

remote: Resolving deltas: 100% (21/21), completed with 4 local objects.

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

remote: error: Trace: de35e860e6f088f7ca549a40b47655df

remote: error: See http://git.io/iEPt8g for more information.

remote: error: File xxx/aaa is 130.82 MB; this exceeds GitHub's file size limit of 100.00 MB

To https://github.com/xxx

 ! [remote rejected] master -> master (pre-receive hook declined)

error: failed to push some refs to 'https://github.com/xxx'

那你可能跟我一樣,是在添加大文件100M之後,並且push失敗了才下載的git lfs並且添加aaa到git lfs的。

只需要放棄之前添加aaa大文件那次的commit,重新提交文件就可以了

 

如何撤回commit,可以參考下面的文章

https://blog.csdn.net/quiet_girl/article/details/79487966

比如我自己的操作:

wodeMacBook-Pro:xxx$ git log

wodeMacBook-Pro:xxx$ git reset --hard ac89782e303fd38f423edc678dec823d43a65f35

wodeMacBook-Pro:xxx$ git lfs track "xxx/aaa"

wodeMacBook-Pro:xxx$ git add .

wodeMacBook-Pro:xxx$ git commit -m "add aaa"

wodeMacBook-Pro:xxx$ git push

2,(Framework文件的上傳) 

如果你是要上傳比較大的framework庫文件,需要主要的是,framework是一個庫文件,二進制文件是包含在裏面的,直接添加framework到git lfs是沒有用的,需要添加里面的二進制文件

比如我想添加GoogleMobileAds.framework

wodeMacBook-Pro:xxx$ git lfs track "XXX/ADs/GoogleMobileAds.framework/GoogleMobileAds"

這樣就可以了 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章