Git LFS is a Git extension developed by Github to implement Git’s support for large files.
Purpose
In the process of program development, binary files occupy a large part of the space. Files such as png and bin are binary, and the size is also very large.
But git’s diff/patch is based on text files. For binary files, git needs to store the changes of each commit.
Every time the binary file is modified and changed, additional submissions will be generated. As a result, the volume of the online warehouse will also grow rapidly.
LFS (Large File Storage) is a tool created to solve this problem.
It saves the large files you marked to another repository, while keeping only lightweight pointers to them in the main repository.
Then when you check out the version, update the corresponding large file according to the change of the pointer. Instead of saving all versions of the large file locally.
Install
Note: Git version not lower than 1.8.5 is required to install Git LFS
Linux
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install
Mac
- Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git-lfs
git lfs install
Windows
- Download and install windows installer
- Run windows installer
- Execute
git lfs install
on the command line
Usage
- Execute
git lfs install
to enable the lfs function - Use the
git lfs track
command to track large files. For example,git lfs track "*.png"
tracks all files with a suffix of png - Use
git lfs track
to view the existing file tracking mode - Committing code requires submitting the
gitattributes
file to the warehouse. It keeps track of the file. You can directly modify this file later to specify the files that LFS needs to track - Run
git lfs ls-files
after submitting to display the list of currently tracked files - After the code is pushed to the remote warehouse, the files tracked by LFS will be displayed in the form of “Git LFS”
- When cloning, you can use ‘git clone’ or
git lfs clone