使用 Git LFS 工具管理大型檔案

前言

以前做的一個作品「藝術與建築索引典」,是一個包含 5 萬多筆詞彙條目的索引典。這些詞彙來自於一個超過 700 MB 的 XML 檔,為了更方便管理這個檔案,因此使用 Git LFS 來把它上傳到 GitHub 上。

安裝

macOS

執行以下指令:

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

Ubuntu

執行以下指令:

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

管理

使用以下指令追蹤指定的大型檔案。

1
git lfs track storage/vocabulary.xml

Git 會新增一個 .gitattributes 檔:

1
storage/vocabulary.xml filter=lfs diff=lfs merge=lfs -text

查看追蹤的大型檔案。

1
git lfs track

推送到 GitHub。

1
2
3
git add .
git commit -m "Add a large file"
git push

如果要從遠端連同大型檔案一起拉取下來,執行以下指令:

1
git lfs clone git@github.com:memochou1993/thesaurus-server.git

如果本地有漏掉的大型檔案要更新,執行以下指令:

1
git lfs pull

程式碼