How to make git LFS not apply to a subdirectory
Asked Answered
Q

4

9

My repository uses git LFS and includes lines such as this one in its .gitattributes:

*.jar filter=lfs diff=lfs merge=lfs -text

There's one .jar file that I want to store in the repo directly, not involving LFS. Ideally, I would make LFS not apply to anything under the directory that contains that jar. Is there a way to do that?

Quadrifid answered 6/8, 2017 at 15:31 Comment(0)
D
11

This answer is largely sourced from this github comment

The syntax for .gitattributes allows you to "minus" an attribute -- removing it from already being included (see: https://git-scm.com/docs/gitattributes#gitattributes-Unset)

This allows you un-lfs a file that was previously included (the example from the github thread):

*.asset filter=lfs diff=lfs merge=lfs -text
Assets/Resources/*.asset -filter=lfs -diff=lfs -merge=lfs -text
Dannielledannon answered 6/8, 2017 at 15:46 Comment(0)
S
3

Something similar to this just worked for us.

*.asset filter=lfs diff=lfs merge=lfs -text
TheAssetIWantToExclude.asset !filter !diff !merge -text

This was for git version 2.17.1.windows.2 today. Comments further in Anthony Sottile's github link provided this answer.

For the existing file we used

git rm --cached TheAssetIWantToExclude.asset
git add TheAssetIWantToExclude.asset
git commit 

to get the file copied to the repo.

Schauer answered 2/7, 2018 at 18:57 Comment(1)
This worked for me with 2.17.1 on Ubuntu, while the accepted answer did not.Disharmonious
H
0

Check out this thread: Track all files in a directory to git LFS but ignore a single folder present in that directory

TL;DR, it's not possible unless you move the folder, or use git lfs track for each individual subdir.

Hyperon answered 6/8, 2017 at 15:45 Comment(1)
Please see my answer for an example that just worked for us on git version 2.17.1.windows.2.Schauer
B
0

Looking through the documentation (https://git-scm.com/docs/gitattributes), I think that the correct syntax is actually:

*.asset filter=lfs diff=lfs merge=lfs -text
Assets/Resources/*.asset -filter -diff -merge -text

Specifically, this part:

Unset <...> this is specified by listing the name of the attribute prefixed with a dash - in the attribute list.

(https://git-scm.com/docs/gitattributes#Documentation/gitattributes.txt-Unset)


More than that, you can define a macro attribute (https://git-scm.com/docs/gitattributes#_defining_macro_attributes) to simplify your .gitattributes file and to make the intent clearer:

[attr]not-lfs -filter -diff -merge -text

*.asset filter=lfs diff=lfs merge=lfs -text
Assets/Resources/*.asset not-lfs
Bartels answered 16/1 at 7:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.