Qndev’s blog

About me Logo

View the Project on GitHub qndev/qndev.github.io

20 June 2019

Git Large File Storage

by NGUYEN DINH QUANG

Bắt đầu với LFS

Yêu cầu

git >= 1.8.2

Cài đặt

Debian

Cấu hình trước khi cài đặt.

Refresh lại các packages trong bộ nhớ đệm bằng cách.

$ sudo apt-get update

Nếu bạn đang sử dụng hệ điều hành Debian cần cài đặt debian-archive-keyring để xác thực các repositories của Debian.

$ sudo apt-get install debian-archive-keyring

Ngoài ra cũng yêu cầu một số tools cần được cài đặt trước khi aifcaif đặt Git LFS.

$ sudo apt-get install curl gnupg apt-transport-https

Cài đặt GPG key bằng cách sử dụng apt-key.

$ curl -L https://packagecloud.io/github/git-lfs/gpgkey | sudo apt-key add -

Cấu hình kho chứa repository bằng cách tạo file /etc/apt/sources.list.d/github_git-lfs.list và chứa thông tin packagecloud repo đưới đây với hai option Linux distribution versionosdist.

$ deb https://packagecloud.io/github/git-lfs/debian/ stretch main
$ deb-src https://packagecloud.io/github/git-lfs/debian/ stretch main

Refresh

$ sudo apt-get update

Cài đặt.

$ 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 OSX

$ brew update
$ brew install git-lfs
$ git lfs install

Ubuntu

$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash

$ sudo apt-get install git-lfs

$ git lfs install

Windows

Download Windows installer

Chạy Windows installer vừa download về

Mở command prompt và chạy git lfs install

Sử dụng Git LFS

Để bắt đầu sử dụng Git LFS trong Git repository chưa được cấu hình cho Git LFS, bạn có thể chỉ ra tệp nào bạn muốn Git LFS quản lý.

$ git lfs track "*.iso"

Ở đây git-lfs sẽ track tất cả các file có dạng *.iso. Để xem danh sách các file có dạng *.typeoffile tracked bởi git-lfs, chỉ cần chạy git lfs track. Để hiển thị tất cả các file đã tracked sau khi commit: git lfs ls-files.

Tiếp theo cần add file .gitattributes vào git repo bởi vì git lfs track lưu trữ khuôn mẫu, file dạng *.typeoffile trong .gitattributes.

$ git add .gitattributes
$ git commit -m "track *.iso files sử dụng Git LFS"

Bây giờ chúng ta có thể thao tác với Git repository như bình thường, và Git LFS sẽ quản lý những files có kichs thước lớn có trong định dạng .gitattributes. Ví dụ add file myfile.iso.

$ git add myfile.iso
$ git commit -m "add myfile.iso"

Note: Nếu files đã có trong history của repository , git lfs track sẽ không quản lý chúng (track). Để làm được diều đó cần sử dụng git lfs migrate. Ví dụ:

$ git lfs migrate import --include="*.iso"

git-lfs-migrate(1).

Để xác định xem file iso vừa commit đã được Git LFS quản lý hay chưa bằng cách:

$ git lfs ls-files
8c15b8b603 * myfile.iso

Cuối cùng push files lên Git remote:

$ git push origin master

Latest Posts

tags: LFS