Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure git-lfs to track files above some size

I have a git repository with git-lfs installed and I would like to have all PDF files above some size in LFS, but not all PDF files, as git-lfs supports. The reason for this is that I have many tiny PDF figure files in vector format which are ok to have in regular version control, and a few large PDFs.

Is it possible to configure git-lfs this way?

I use git from Atlassian source-tree and host the repository in bitbucket, maybe those support this more advanced use-case?

like image 377
Uri Cohen Avatar asked Jun 11 '19 09:06

Uri Cohen


People also ask

Does git LFS have a limit?

There is currently a 10 GB size limit for the file upload into the media storage. Uploading files larger than 10 GB will result in an error. Use the Git LFS extension with a repository to speed up the handling of large files.

Does git LFS reduce size?

Git LFS (Large File Storage) is a Git extension developed by Atlassian, GitHub, and a few other open source contributors, that reduces the impact of large files in your repository by downloading the relevant versions of them lazily.


1 Answers

Unfortunately, this is not possible on git-lfs. See issue #282.

There is however a hack provided by user Baccanno, but I wouldn't recommend it for repositories with many files. It tracks all files above a threshold, but it could be modified to do it for PDF's only.

The hack:

(Copied here without warranty)

Put this in the [alias] section of your git config (project_root/.git/config) and change the 300k at the end to the size you wish

track-large = !"git st --porcelain --ignore-submodules | grep -v \"D \" | awk '{ l=length($0); s=substr($0,4,l-1); print s}' | sed -n 's/\\(\\(.* -> *\\)\\|\\)\\(.*\\)/\\3/p' | xargs -I{} find {} -size +300k | xargs -I{} git lfs track \"{}\""
like image 139
abrac Avatar answered Sep 28 '22 14:09

abrac