Git is great for tracking text files like code, but it doesn't handle binary files (images, fonts, videos, PDFs) well. Every version of a binary file is stored in full inside the repository, which quickly bloats the repo size and slows down cloning. Git 非常擅長追蹤程式碼等文字檔案,但它不擅長處理二進位檔案(圖片、字型、影片、PDF)。每個二進位檔案的每個版本都會完整儲存在 repository 中,這會迅速膨脹 repo 大小並拖慢 clone 速度。 Git 非常擅长追踪代码等文本文件,但它不擅长处理二进制文件(图片、字体、视频、PDF)。每个二进制文件的每个版本都会完整存储在仓库中,这会迅速膨胀仓库大小并拖慢 clone 速度。 Magaling ang Git sa pag-track ng text files tulad ng code, pero hindi nito magandang hina-handle ang binary files (images, fonts, videos, PDFs). Bawat version ng binary file ay buo ang storage sa repository, na mabilis nagpapalaki ng repo at nagpapabagal ng cloning.
Git LFS (Large File Storage) solves this by replacing binary files in your repo with small pointer files. The actual file content is stored separately on the server. Git LFS(Large File Storage)的解決方式是將 repo 中的二進位檔案替換為小型指標檔案(pointer files)。實際的檔案內容則獨立儲存在伺服器上。 Git LFS(Large File Storage)的解决方式是将仓库中的二进制文件替换为小型指针文件(pointer files)。实际的文件内容则独立存储在服务器上。 Ang Git LFS (Large File Storage) ay niresolba ito sa pamamagitan ng pagpapalit ng binary files sa iyong repo ng maliliit na pointer files. Ang aktwal na file content ay hiwalay na sine-store sa server.
When you clone or checkout, LFS automatically downloads the real files and puts them in the right place. Your workflow doesn't change at all — file paths stay the same, and git add, git commit, and git push work as normal.
當你 clone 或 checkout 時,LFS 會自動下載真正的檔案並放到正確的位置。你的工作流程完全不會改變 — 檔案路徑不變,git add、git commit 和 git push 照常運作。
当你 clone 或 checkout 时,LFS 会自动下载真正的文件并放到正确的位置。你的工作流程完全不会改变 — 文件路径不变,git add、git commit 和 git push 照常运作。
Kapag nag-clone o nag-checkout ka, awtomatikong dina-download ng LFS ang totoong files at inilalagay sa tamang lugar. Hindi nagbabago ang iyong workflow — pareho pa rin ang file paths, at gumagana pa rin ang git add, git commit, at git push nang normal.
Install Git LFS for your operating system: 為你的作業系統安裝 Git LFS: 为你的操作系统安装 Git LFS: I-install ang Git LFS para sa iyong operating system:
$ brew install git-lfs
$ winget install GitHub.GitLFS
$ sudo apt install git-lfs
After installing, run the one-time setup command. This configures Git to use LFS filters globally: 安裝完成後,執行一次性設定指令。這會將 LFS 過濾器全域設定到 Git 中: 安装完成后,执行一次性设置命令。这会将 LFS 过滤器全局配置到 Git 中: Pagkatapos i-install, i-run ang one-time setup command. Iko-configure nito ang Git para gamitin ang LFS filters nang global:
$ git lfs install
Git LFS initialized.
Verify the installation: 驗證安裝是否成功: 验证安装是否成功: I-verify ang installation:
$ git lfs version
git-lfs/3.x.x (GitHub; ...)
git lfs install once per machine. It applies to all repositories on your computer.
你只需要在每台電腦上執行一次 git lfs install。它會套用到你電腦上的所有 repository。
你只需要在每台电脑上执行一次 git lfs install。它会应用到你电脑上的所有仓库。
Isang beses lang kailangan i-run ang git lfs install sa bawat machine. Maa-apply ito sa lahat ng repositories sa iyong computer.
If Git LFS is installed on your machine, cloning a repo with LFS-tracked files works automatically. The LFS files are downloaded as part of the clone process. 如果你的電腦已安裝 Git LFS,clone 含有 LFS 追蹤檔案的 repo 會自動運作。LFS 檔案會作為 clone 過程的一部分被下載。 如果你的电脑已安装 Git LFS,clone 含有 LFS 追踪文件的仓库会自动运作。LFS 文件会作为 clone 过程的一部分被下载。 Kung naka-install ang Git LFS sa iyong machine, awtomatikong gumagana ang pag-clone ng repo na may LFS-tracked files. Dina-download ang LFS files bilang bahagi ng clone process.
Just run git clone as usual. LFS files are pulled automatically:
照常執行 git clone 即可。LFS 檔案會自動拉取:
照常执行 git clone 即可。LFS 文件会自动拉取:
I-run lang ang git clone tulad ng dati. Awtomatikong pini-pull ang LFS files:
Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and select Git: Clone. Paste the repository URL and choose a folder. VSCode uses your system Git, so LFS works automatically.
開啟命令面板(Ctrl+Shift+P / Cmd+Shift+P),選擇 Git: Clone。貼上 repository URL 並選擇資料夾。VSCode 使用系統的 Git,所以 LFS 會自動運作。
打开命令面板(Ctrl+Shift+P / Cmd+Shift+P),选择 Git: Clone。粘贴仓库 URL 并选择文件夹。VSCode 使用系统的 Git,所以 LFS 会自动运作。
Buksan ang Command Palette (Ctrl+Shift+P / Cmd+Shift+P) at piliin ang Git: Clone. I-paste ang repository URL at pumili ng folder. Gumagamit ang VSCode ng system Git, kaya awtomatikong gumagana ang LFS.
git-lfs is installed and git lfs install has been run, LFS will work seamlessly in VSCode.
VSCode 使用系統安裝的 Git。只要已安裝 git-lfs 並執行過 git lfs install,LFS 就能在 VSCode 中無縫運作。
VSCode 使用系统安装的 Git。只要已安装 git-lfs 并执行过 git lfs install,LFS 就能在 VSCode 中无缝运作。
Gumagamit ang VSCode ng Git installation ng iyong system. Basta naka-install ang git-lfs at na-run na ang git lfs install, seamlessly gagana ang LFS sa VSCode.
Go to File → New → Project from Version Control. Paste the repository URL, choose a directory, and click Clone. WebStorm uses your system Git, so LFS works automatically. 前往 File → New → Project from Version Control。貼上 repository URL,選擇目錄,然後點擊 Clone。WebStorm 使用系統的 Git,所以 LFS 會自動運作。 前往 File → New → Project from Version Control。粘贴仓库 URL,选择目录,然后点击 Clone。WebStorm 使用系统的 Git,所以 LFS 会自动运作。 Pumunta sa File → New → Project from Version Control. I-paste ang repository URL, pumili ng directory, at i-click ang Clone. Gumagamit ang WebStorm ng system Git, kaya awtomatikong gumagana ang LFS.
git-lfs is installed on your machine.
WebStorm 也使用系統安裝的 Git。只要電腦上已安裝 git-lfs,LFS 整合就會自動進行。
WebStorm 也使用系统安装的 Git。只要电脑上已安装 git-lfs,LFS 集成就会自动进行。
Gumagamit din ang WebStorm ng Git installation ng iyong system. Awtomatiko ang LFS integration kapag naka-install ang git-lfs sa iyong machine.
When you add a new binary file type to the project, you need to tell LFS to track it first. Then you can add and commit files as normal. 當你要在專案中新增一種二進位檔案類型時,需要先告訴 LFS 追蹤它。然後就可以照常新增和提交檔案。 当你要在项目中添加一种二进制文件类型时,需要先告诉 LFS 追踪它。然后就可以照常添加和提交文件。 Kapag nagdadagdag ka ng bagong binary file type sa project, kailangan mong sabihin muna sa LFS na i-track ito. Pagkatapos ay pwede ka nang mag-add at mag-commit ng files nang normal.
First, track the file extension with LFS, then commit the .gitattributes file. After that, add your binary file normally:
首先用 LFS 追蹤該副檔名,然後提交 .gitattributes 檔案。之後就可以正常新增你的二進位檔案:
首先用 LFS 追踪该扩展名,然后提交 .gitattributes 文件。之后就可以正常添加你的二进制文件:
Una, i-track ang file extension gamit ang LFS, pagkatapos i-commit ang .gitattributes file. Pagkatapos noon, i-add ang iyong binary file nang normal:
Use the integrated terminal at the bottom of VSCode to run the git lfs track command. Then use the Source Control sidebar to stage and commit:
使用 VSCode 底部的整合終端機執行 git lfs track 指令。然後使用左側的 Source Control 面板來暫存和提交:
使用 VSCode 底部的集成终端执行 git lfs track 命令。然后使用左侧的 Source Control 面板来暂存和提交:
Gamitin ang integrated terminal sa ibaba ng VSCode para i-run ang git lfs track command. Pagkatapos gamitin ang Source Control sidebar para i-stage at i-commit:
Use the Terminal tab at the bottom of WebStorm to run git lfs track. Then use the Commit tool window to stage and commit your files:
使用 WebStorm 底部的 Terminal 分頁執行 git lfs track。然後使用 Commit 工具視窗來暫存和提交你的檔案:
使用 WebStorm 底部的 Terminal 标签执行 git lfs track。然后使用 Commit 工具窗口来暂存和提交你的文件:
Gamitin ang Terminal tab sa ibaba ng WebStorm para i-run ang git lfs track. Pagkatapos gamitin ang Commit tool window para i-stage at i-commit ang iyong mga files:
.gitattributes before committing the binary files. This ensures other team members' LFS configuration is updated when they pull your changes.
請務必在提交二進位檔案之前先提交 .gitattributes。這樣其他團隊成員拉取你的改動時,LFS 設定也會一同更新。
请务必在提交二进制文件之前先提交 .gitattributes。这样其他团队成员拉取你的改动时,LFS 配置也会一同更新。
Laging i-commit muna ang .gitattributes bago i-commit ang binary files. Sisiguraduhin nito na ma-update ang LFS configuration ng ibang team members kapag ni-pull nila ang iyong mga pagbabago.
Our projects use Husky to run a pre-commit hook that blocks binary files not tracked by Git LFS. This prevents accidental commits of large binary files that would bloat the repository. 我們的專案使用 Husky 執行 pre-commit hook,會阻擋未被 Git LFS 追蹤的二進位檔案。這可以防止意外提交大型二進位檔案而膨脹 repository。 我们的项目使用 Husky 执行 pre-commit hook,会阻止未被 Git LFS 追踪的二进制文件。这可以防止意外提交大型二进制文件而膨胀仓库。 Gumagamit ang ating mga projects ng Husky para mag-run ng pre-commit hook na bini-block ang binary files na hindi tracked ng Git LFS. Pinipigilan nito ang aksidenteng pag-commit ng malalaking binary files na magpapalaki ng repository.
If you see an error like this when committing: 如果你在 commit 時看到這樣的錯誤: 如果你在 commit 时看到这样的错误: Kung makakita ka ng error na ganito kapag nag-commit:
$ git commit -m "feat: add product images"
ERROR: assets/product-photo.psd is binary but not tracked by Git LFS.
Run: git lfs track '*.psd'
Then: git add .gitattributes
Commit blocked by pre-commit hook.
This means you need to track the file extension with LFS first. Follow these steps to fix it: 這表示你需要先用 LFS 追蹤該副檔名。按照以下步驟修正: 这表示你需要先用 LFS 追踪该扩展名。按照以下步骤修正: Ibig sabihin nito na kailangan mo munang i-track ang file extension gamit ang LFS. Sundin ang mga hakbang na ito para i-fix:
Step 1: Track the file type with LFS: 步驟一:用 LFS 追蹤該檔案類型: 步骤一:用 LFS 追踪该文件类型: Step 1: I-track ang file type gamit ang LFS:
$ git lfs track '*.psd'
Tracking "*.psd"
Step 2: Stage and commit .gitattributes:
步驟二:暫存並提交 .gitattributes:
步骤二:暂存并提交 .gitattributes:
Step 2: I-stage at i-commit ang .gitattributes:
$ git add .gitattributes
$ git commit -m "chore: track PSD files with LFS"
Step 3: Now retry your original commit: 步驟三:現在重新嘗試你原本的 commit: 步骤三:现在重新尝试你原本的 commit: Step 3: Ngayon i-retry ang iyong orihinal na commit:
$ git add assets/product-photo.psd
$ git commit -m "feat: add product images"
*.psd, *.ai, *.pdf, *.png, *.jpg, *.gif, *.mp4, *.mov, *.zip, *.woff2, *.ttf, *.otf.
常見需要用 LFS 追蹤的檔案類型包括:*.psd、*.ai、*.pdf、*.png、*.jpg、*.gif、*.mp4、*.mov、*.zip、*.woff2、*.ttf、*.otf。
常见需要用 LFS 追踪的文件类型包括:*.psd、*.ai、*.pdf、*.png、*.jpg、*.gif、*.mp4、*.mov、*.zip、*.woff2、*.ttf、*.otf。
Mga karaniwang file types na dapat i-track gamit ang LFS: *.psd, *.ai, *.pdf, *.png, *.jpg, *.gif, *.mp4, *.mov, *.zip, *.woff2, *.ttf, *.otf.
Quick reference of the most common Git LFS commands: 最常用的 Git LFS 指令速查表: 最常用的 Git LFS 命令速查表: Mabilis na reference ng pinaka-karaniwang Git LFS commands:
| Command 指令 命令 Command | What it does 作用 作用 Ano ang ginagawa |
|---|---|
git lfs install |
One-time setup per machine 每台電腦一次性設定 每台电脑一次性设置 One-time setup sa bawat machine |
git lfs track '*.ext' |
Track a file type with LFS 用 LFS 追蹤某種檔案類型 用 LFS 追踪某种文件类型 I-track ang file type gamit ang LFS |
git lfs untrack '*.ext' |
Stop tracking a file type 停止追蹤某種檔案類型 停止追踪某种文件类型 Ihinto ang pag-track ng file type |
git lfs ls-files |
List all LFS-tracked files 列出所有 LFS 追蹤的檔案 列出所有 LFS 追踪的文件 Ilista lahat ng LFS-tracked files |
git lfs pull |
Download LFS files from server 從伺服器下載 LFS 檔案 从服务器下载 LFS 文件 I-download ang LFS files mula sa server |
git lfs prune |
Remove old local LFS cache 清除本地舊的 LFS 快取 清除本地旧的 LFS 缓存 Alisin ang lumang local LFS cache |
cat .gitattributes |
See what file types are tracked 查看哪些檔案類型被追蹤 查看哪些文件类型被追踪 Tingnan kung anong file types ang tracked |
You now know how to use Git LFS to manage binary files efficiently. Check out the Git Daily Workflow guide for general Git usage. 你現在已經知道如何使用 Git LFS 來高效管理二進位檔案。可以參考 Git 日常工作流程指南了解一般的 Git 使用方式。 你现在已经知道如何使用 Git LFS 来高效管理二进制文件。可以参考 Git 日常工作流程指南了解一般的 Git 使用方式。 Alam mo na ngayon kung paano gamitin ang Git LFS para ma-manage nang maayos ang binary files. Tingnan ang Git Daily Workflow guide para sa pangkalahatang Git usage.