Skip to content

Git LFS

一句话解释

Git LFS(大文件存储)用文本指针替换仓库中的大文件,实际内容存于独立服务器。

用大白话说

Git LFS(大文件存储)是一个扩展,让 Git 高效处理大文件——视频、数据集、图形、二进制。它不在 Git 对象存储中存完整文件(那会膨胀仓库并拖慢每次克隆),而是在 Git 中存一个小指针文件,真实内容存于独立 LFS 服务器。克隆时,LFS 随仓库下载指针文件,再按需拉取实际大文件(或用 git lfs pull 一次全拉)。这使仓库对文本操作保持小而快,同时仍对大文件版本化。.gitattributes 标记哪些路径用 LFS。LFS 需服务端支持(GitHub、GitLab、Bitbucket 均提供,有配额)。未装 LFS 扩展时,克隆只得指针。LFS 适用于偶尔变化的几兆以上文件——不适用于频繁变化的大文件,那会使 LFS 存储快速增长。

示例

bash
# Install Git LFS (once per machine)
git lfs install

# Track large file types — updates .gitattributes
git lfs track "*.psd"
git lfs track "*.mp4"
git lfs track "data/*.csv"

# Commit the .gitattributes, then add large files normally
git add .gitattributes
git add design.psd
git commit -m "add design file"

# Clone pulls pointers; fetch real content
git lfs pull

git lfs track 标记用 LFS 存储的模式。真实内容进 LFS 服务器;Git 存指针。lfs pull 下载实际文件。

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表