Reputation: 3406
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.
Upvotes: 73
Views: 69738
Reputation: 1896
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
.
Upvotes: 61
Reputation: 460
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.
Upvotes: 9
Reputation: 45679
Include the path to the file, instead of just the filename.
Upvotes: 25