Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I exclude some files from git-lfs?

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.

like image 748
Max Avatar asked Aug 21 '19 15:08

Max


People also ask

How do I exclude a .Git file?

Use your favorite text editor to open the file called . git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.

What is Git LFS prune?

DESCRIPTION. Deletes local copies of LFS files which are old, thus freeing up disk space.


2 Answers

.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.

like image 98
rkedge Avatar answered Oct 24 '22 14:10

rkedge


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.

like image 23
xiay Avatar answered Oct 24 '22 15:10

xiay