Configure git-lfs to track files above some size
Asked Answered
N

2

17

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?

Noh answered 11/6, 2019 at 9:20 Comment(3)
Have you found a solution to this?Roz
Didn't find a solution, no.Noh
Annoying, I have the same problem. But thanks for responding so quicklyRoz
P
6

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 \"{}\""
Pinnatipartite answered 8/7, 2020 at 13:12 Comment(1)
Thanks, I'm the original author, it's suboptimal and I went from this to a more dense .gitattribute that covers all the binaries in our game. The only issue remaining is with Unity files that are text based (which is good), such as .asset, but that can get greatly vary in size (which is bad). You'd have the same issue with any text based representation of large data. In this case I would still recommend to check them manually with this kind of workaround, or any similar such as this lfs-auto-track repo (didn't check it myself)Ark
D
0

If files bigger than the size when commit, to automatically run git lfs track files , you can use this npm module: lfs-auto-track

The source code here:

lfs-auto-track

And check the image example screenshot(it's works): image screenshot

I already use this module in my projects, and it's work well.

Desantis answered 19/4 at 12:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.