Git large file Management

Source: Internet
Author: User

Since git saves the entire file system in commit, if there are some large binary files in the file system, compared to slices, video, then your repo will become very large, and clone will consume more and more time when this repo. Is there any way to optimize the problem?

One possible way is to use Git-fat:https://github.com/jedbrown/git-fat

The principle is that the binary file itself is stored in the shared file system, and the information stored in git repo is just some meta data.

1. Install: Git-fat is a shell script, just download the script and put it in your PATH variable to install it.

2. Use: Create a. gitattributes file to describe which files are a binary file:

$ cd path-to-your-cat >> gitattributes*.png filter=fat-CRLF*.jpg filter= Fat-CRLF*.gz  filter=fat-CRLF^d

Run git fat init to activate the file suffix above, so you can git add as a general file, Git commits those. png,.gz,.jpg files, and the file itself is stored in a place outside of repo;

If your file itself is saved on a shared server, you can create a. gitfat file that writes the following content to the file

= your.remote-host.org:/share/fat-= yourusername

Here is the process for saving files locally and related commands:

$ git init repoinitialized empty git repositoryinch/tmp/repo/.git/$ cd repo$ git fat init$Cat>. Gitfat[rsync]remote= localhost:/tmp/fat-store$mkdir-p/tmp/fat-store # Makesure the remote directory exists$Echo '*.gz Filter=fat-crlf'>. gitattributes$ git Add. gitfat. gitattributes$ git commit-M'Initial Repository'[Master (Root-commit) EB7FACB] Initial repository2Files changed,3Insertions (+) Create mode100644. gitattributes Create mode100644. gitfat$ Curl https://Nodeload.github.com/jedbrown/git-fat/tar.gz/master-o master.tar.gz% Total% Received%xferd Average Speed time time dload Upload Total spent left Speed -  6449   -  6449    0     0   7741      0--:--:-- --:--:-- --:--:--9786$ git add master.Tar. Gzgit-fat filter-clean:caching to/tmp/repo/.git/fat/objects/b3489819f81603b4c04e8ed134b80bace0810324$ git commit-M'Added master.tar.gz'[Master b85a96f] Added master.Tar. Gzgit-fat filter-clean:caching to/tmp/repo/.git/fat/objects/b3489819f81603b4c04e8ed134b80bace08103241 fileChanged1Insertion (+) Create mode100644Master.Tar. gz$ git show--pretty=oneline head918063043a6156172c2ad66478c6edd5c7df0217 Add master.Tar. GZdiff--git A/master.Tar. GZ B/master.Tar. GznewfileMode100644Index0000000.. 12f7d52---/dev/NULL+ + + B/master.Tar. gz@@-0,0+1 @@+#$# git-fat 1f218834a137f7b185b498924e7a030008aee2ae$ git fat pushpushing to localhost:/tmp/fat-storebuildingfileList ...1 fileTo considersent ABytes Received Abytes48.67bytes/sectotal size is6449Speedup is88.34

After the above process is complete, the corresponding binary files are already saved, then how to use them?

$ CD. $ git clone repo repo2cloning into'Repo2'... Done. $ cd repo2$ git fat init # don't Forget$ls-L #fileIs just a placeholdertotal4-rw-r--r--1Jed Users -Nov -  A: theMaster.Tar. gz$CatMaster.Tar. GZ # holds the SHA1 of thefile#$# git-fat 1f218834a137f7b185b498924e7a030008aee2ae$ git fat pullreceivingfileList ...1 fileTo Consider1f218834a137f7b185b498924e7a030008aee2ae6449  -%6.15mb/s0:xx:xx(xfer#1, to-check=0/1) sent -Bytes Received6558bytes4392.00bytes/sectotal size is6449Speedup is0.98Restoring 1f218834a137f7b185b498924e7a030008aee2ae, Master.Tar. Gzgit-fat filter-smudge:restoring from/tmp/repo2/.git/fat/objects/1f218834a137f7b185b498924e7a030008aee2ae$ git statusgit-fat filter-clean:caching to/tmp/repo2/.git/fat/objects/1f218834a137f7b185b498924e7a030008aee2ae# on Branch masternothing to commit, working directory clean$ls-L # recovered the fullfile Total8-rw-r--r--1Jed Users6449Nov -  -:TenMaster.Tar. gz

Git large file Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.