Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I always exclude text attribute for git LFS files?

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
like image 567
C0DEF52 Avatar asked Dec 08 '19 15:12

C0DEF52


People also ask

What is the purpose of Gitattributes file?

gitattributes file allows you to specify the files and paths attributes that should be used by git when performing git actions, such as git commit , etc. In other words git automatically saves the file according to the attributes specified, every time a file is created or saved.

Is git LFS necessary?

You should use Git LFS if you have large files or binary files to store in Git repositories. That's because Git is decentralized. So, every developer has the full change history on their computer.

Are git LFS files versioned?

Git Large File Storage Git LFS takes advantage of this centralized pattern. Large files are stored in the cloud, and these files are referenced via pointers in local copies of the repo. When a clone or pull occurs, the appropriate version of the file is downloaded from the remote.


Video Answer


2 Answers

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.

like image 192
bk2204 Avatar answered Oct 17 '22 23:10

bk2204


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

like image 34
Rob Dunbar Avatar answered Oct 18 '22 00:10

Rob Dunbar