Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a single file to GIT LFS?

Tags:

git

git-lfs

How can I add just a single file to GIT LFS?

Most examples show adding a pattern that specifies which files to add to LFS. However, I wish to add single file. If, for example, I do

git lfs track "file.bin"

this will track all files named file.bin regardless of what directory they are in.

I considered adding an exclusion filter (! pattern) to .gitattributes so exclude all directories but that is not supported.

The best I've done so far is to track the file pattern for the file I want to add, add the file and then remove the tracking of that file pattern. This is a little fiddly. Is there a better way?

I want to express the file pattern $ROOT_OF_GIT_REPO/file.bin but am lacking a way to express the $ROOT_OF_GIT_REPO part.

like image 736
user2746401 Avatar asked Aug 17 '18 15:08

user2746401


People also ask

How do I track a file in Git LFS?

To do so, run git lfs track “*. For example, if all csv files need to be tracked, run git lfs track “*. csv” or if all jpeg image files need to be tracked, run git lfs track “*. jpg”.

What is git LFS file?

Git LFS (Large File Storage) is a Git extension developed by Atlassian, GitHub, and a few other open source contributors, that reduces the impact of large files in your repository by downloading the relevant versions of them lazily.

Where are LFS files stored?

Git LFS objects can be large in size. By default, they are stored on the server GitLab is installed on.


3 Answers

Include the path to the file, instead of just the filename.

like image 90
Mark Adelsberger Avatar answered Oct 29 '22 04:10

Mark Adelsberger


Use:

git lfs track --filename [file path]

Source: git lfs track --help

--filename

Treat the arguments as literal filenames, not as patterns. Any special glob characters in the filename will be escaped when writing the .gitattributes file.

This option has been available since v2.9.0 of the LFS extension (pull request). You can check your local version: git lfs version.

like image 25
Pamphile Avatar answered Oct 29 '22 03:10

Pamphile


You can specify any filename or path in your repository. You aren't limited to using file extensions. You could also track a specific directory with git lfs track 'assets/*' or an entire directory tree with git lfs track 'assets/**/*'. You could also track individual files specifically with git lfs track path/to/file which will track only that file.

like image 7
AlexanderKomarov Avatar answered Oct 29 '22 04:10

AlexanderKomarov