26

I created a repo with some image files. I have .gitignore and .gitattributes that I want to exclude from lfs. So I need to track all files by lfs but not .gitignore and .gitattributes.

I' m using Sourcetree and I tried that in .gitattributes:

.gitignore text .gitattributes text * filter=lfs diff=lfs merge=lfs -text 

But all of my files getting tracked by lfs.

1

3 Answers 3

33

I was looking for the same. I am using git version 2.26.2 and rkedge's answer did not work for me. I found this thread and ended up using:

*.dat filter=lfs diff=lfs merge=lfs -text excluded.dat !filter !diff !merge text 

For files already commited, I had to untrack and re-commit them after modifying .gitattributes.

Sign up to request clarification or add additional context in comments.

Comments

27

.gitattributes works similarly to .gitignore in terms of precedence.

* filter=lfs diff=lfs merge=lfs -text .gitignore filter= diff= merge= text .gitattributes filter= diff= merge= text 

This will unset the filter, diff, merge for those files, and lfs won't track them.

3 Comments

This is the answer that should be accepted. I omitted the second line .gitignore filter= diff= merge= text in my repository where I use git to backup my photos.
I had issues with this syntax using pre-commit-hooks. Using ! as suggested below solved the issue
After updating the .gitattributes file, how do I replace the local files with their dereferenced content (instead of the git-lfs reference)?
-3

Unlike a .gitignore file, a .gitattributes file doesn't have exclude patterns, so there isn't a way to specify that all files except for a few should have a filter (like Git LFS) applied.

You'll need to specify your files in a different way. If all your files are in a directory (say, foo), you can specify foo/**. If they're all images, you could specify a rule for each type of image (say, one for *.png, one for *.jpg, and one for *.gif).

As a final suggestion, if they all start with an alphabetical or numerical character, you could specify [A-Za-z0-9]*, which would exclude all of the dot files as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.