Should I always exclude text attribute for git LFS files?
Asked Answered
P

2

14

There are a lot of articles in the web saying it is a good practice to place binary files under LFS. So, .gitattributes file will look like this:

## Fonts
*.otf filter=lfs diff=lfs merge=lfs -text
*.OTF filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.TTF filter=lfs diff=lfs merge=lfs -text

Note that all the entries contain -text which tells git to not treat these files as text files and treat them as binary.

Now, let's say I want to track some text files with extension *.yaml as LFS because they are very large but still text based. Should I create entries in the same way as for binary ones or should I omit -text like this?

*.yaml filter=lfs diff=lfs merge=lfs
*.YAML filter=lfs diff=lfs merge=lfs
Proust answered 8/12, 2019 at 15:38 Comment(0)
E
15

Yes, you always want to exclude the text attribute for files using Git LFS. The reason is that you don't want the pointer files stored in the repository to be subject to line-ending conversions or encoding changes, since that would make them invalid, nor do you want that for the large files, since that makes the hash change and therefore the underlying pointer file change as well. The text attribute controls these aspects, and therefore it should be disabled.

Ethology answered 8/12, 2019 at 22:44 Comment(0)
A
9

FYI -text means unset the text attribute i.e.

# Treat *.otf as **not** text
*.otf filter=lfs diff=lfs merge=lfs -text
# Treat *.otf as text
*.otf filter=lfs diff=lfs merge=lfs text

Leaving -text out will then use what ever default you have set in your .gitattributes file. So probably better to leave -text imo

See https://git-scm.com/docs/gitattributes#_end_of_line_conversion

Anastase answered 23/11, 2021 at 3:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.