Git Large File Storage

Git 進階

Amanda Crawford-Adamo

Software and Data Engineer

什麼是 Git Large File System?

Git LFS 指令:

git lfs
  • Git LFS:Git Large File Storage
  • 以指標取代大型檔案於 repo
  • 使用小型指標檔
  • 大型檔案與 repo 分離儲存

優點:

  1. 降低儲存庫大小
  2. 更快的 clone 與 fetch
  3. 高效處理二進位檔
  4. 大型檔協作更順暢
Git 進階

Git LFS 初始化流程

  • 初始化 Git LFS

    git lfs install
    
  • 設定要追蹤的檔案並產生 .gitattributes

    git lfs track "*.csv"
    
  • 將含追蹤設定的 .gitattributes 加入 index

    git add .gitattributes
    
  • 提交變更
    git commit -m "Track CSV files"
    

檔案櫃抽屜升起的動態圖片

Git 進階

Git LFS 更新流程

  1. git add 新增檔案
    git add large_file.csv
    
  2. 提交並推送變更
    git commit -m "Update large CSV file"
    git push origin main
    
  3. 下載更新
    git pull
    git lfs pull  # 若需明確下載 LFS 內容
    
Git 進階

何時使用 Git LFS

適用情境:

  1. 需追蹤大型資料集(CSV、JSON 等)的變更
  2. 機器學習模型
  3. 二進位資產(圖片、影片)
  4. 版控壓縮檔或安裝程式

不適用情境:

  1. 很少更新的大型檔
  2. 小型文字檔,如程式碼
  3. 儲存空間配額很緊
Git 進階

最佳實務

  1. 高效管理大型檔案
  2. 提升資料密集專案的協作
  3. 與 Git 流程無縫整合

小撇步:

  1. 有選擇地追蹤檔案
  2. 讓團隊知悉 LFS 使用情況
  3. 定期清理 LFS 快取
Git 進階

一起來練習吧!

Git 進階

Preparing Video For Download...