remote: error: GH001: Large files detected.
remote: error: Trace: 7b7de6b9372ee392e0f3961b05ea6f33
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File *.framework/Versions/A/* is 207.25 MB; this exceeds GitHub's file size limit of 100.00 MB
在使用Git時,你是否遇到過這種問題?遇到這種問題后又該如何操作呢?
解決這個大文件上傳問題目前有兩種方法(還有一種支持上傳大文件客戶端Tower,免費破解版在文末公眾號):
1. 刪除大于100M的文件,不上傳大文件(上傳成功后在本地添加大文件)或使用.gitignore忽略文件,這里我忽略pods引入的所有文件
.gitignore內(nèi)容
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xccheckout
!default.xcworkspace
#CocoaPods
Pods
!Podfile
!Podfile.lock
1-1. 刪除磁盤緩存
git rm --cached或git rm -r --cached
1-2. 將大文件從commit記錄中移除且以后commit都將不會再將其commit
git commit --amend -CHEAD
1-3. 推送至遠程服務(wù)器
git push origin master(第一次推送時命令)或git push
2. 突破大文件上傳限制,使用git-lfs(Git Large File Storage)(原地址)

Git Large File Storage(LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.
譯:Git Large File Storage(LFS)用Git內(nèi)部的文本指針替換大文件,如音頻樣本、視頻、數(shù)據(jù)集和圖形,同時將文件內(nèi)容存儲在遠程服務(wù)器上,如GitHub.com或GitHub Enterprise。
2-1. 安裝,我是用的是Macbook Pro,所以選擇macOS用戶安裝方式 Homebrew 安裝
brew install git-lfs
2-2. 打開終端,cd到git倉庫本地路徑,初始化lfs
git lfs install
2-3. 追蹤單個文件
git lfs track
eg:git lfs track "*.psd"
2-4. 添加lfs追蹤文件,提交倉庫(此處一定要先提交追蹤文件到倉庫,在提交其他文件)
git add .gitattributes
git commit -m "track *.psd files using Git LFS"
git add .
git commit -m "submit other files"
2-5. 驗證是否追蹤大文件,如果輸入后不顯示則追蹤不成功
git lfs ls-files
2-6. 推送至遠程倉庫
git push origin master
Uploading LFS objects: 100% (1/1), 810 B, 1.2 KB/s
# ...
To https://github.com/git-lfs/git-lfs-test
67fcf6a..47b2002 master -> master
目前OSChina僅支持付費企業(yè)支持,個人需通過郵件 git@oschina.cn 聯(lián)系支持(fls說明),GitLab需在項目設(shè)置中手動開啟此功能,本項目我是以GitHub私人項目實驗。

2019.6.20更新
目前已拋棄第二種方法。由于github的Git LFS Data的免費存儲空間為1GB,超出了要付費,每月大概5 Dollor,所以我選擇了第一種方式上傳大文件忽略大文件上傳。
注意:
Q1:上傳成功后,拉取工程報錯,有的文件中出現(xiàn)如下信息(GitHub git-lfs Issue 我試了好像不是這個原因造成的,可以拉取下來,但是會提交不了)
version https://git-lfs.github.com/spec/v1
oid sha256:446a6063f3b698c388700d
size 1127229450
Q1 解決方案:
造成此問題的原因是可能是framework文件追蹤不成功導(dǎo)致的(我是因為這個導(dǎo)致的)可看Q2如何追蹤framework文件。刪除GitHub倉庫,按照lfs方法的流程重新來一遍即可。
Q2:framework超過100M的文件如何上傳?然而lfs的作者并沒有給出答案,只是讓去看文檔!
提示錯誤如下
emote: error:
File *.framework/Versions/A/* is 207.25 MB;
this exceeds GitHub's file size limit of 100.00 MB
Q2 解決方案:
按照錯誤提示追蹤framework庫,因為macOS系統(tǒng)會將其看成一個文件夾
git lfs track "*.framework/Versions/A/*"
注意提交追蹤文件后驗證一下
git lfs ls-files
附:下載地址
關(guān)注微信公眾號:商丘IT圈,回復(fù)tower即可免費獲取。