Sub topic 6
Inspecting what LFS is managing
This chapter assumes you can clone, commit, and push with Git, and that you have already installed Git LFS and tracked at least one pattern with git lfs track. You also need to know what .gitattributes does and what an LFS pointer file looks like. Here you learn to ask LFS three questions. Which files does it manage? What is the state of those files right now? Which patterns decide that?
Why inspection matters
Git LFS works through filters, so ordinary Git commands often hide what is happening. A file called logo.psd looks the same in your editor whether the working tree holds the real 40 MB file or a 130-byte pointer. git status reports changes in terms of Git objects, which means it can't tell you whether the big content has been uploaded.
The LFS commands answer these questions directly:
git lfs trackprints the patterns in effect.git lfs ls-fileslists the files LFS manages.git lfs statusshows LFS-specific staged and unstaged changes.
git lfs ls-files
git lfs status
git lfs trackRun these when something looks wrong, and also before a push, because they show you what is about to be uploaded.
Listing tracked patterns with `git lfs track`
With no arguments, git lfs track does not change anything. It prints every pattern that the .gitattributes files in your repository currently route through LFS, and the file each pattern comes from.
Listing tracked patterns
*.psd (.gitattributes)
textures/*.png (.gitattributes)
Listing excluded patternsThe line behind each entry in .gitattributes looks like this:
*.psd filter=lfs diff=lfs merge=lfs -textThree things are worth noticing:
- The pattern is the unit of tracking, not the individual file. A new
.psdfile is picked up automatically. - The source file in parentheses tells you which
.gitattributesit was defined in. Patterns can live in subdirectories, so this helps when a rule seems to come from nowhere. - The "excluded patterns" section lists patterns marked with
-filter, which opt files out of LFS. It is usually empty.
A pattern only affects files when they are added. Tracking *.psd today does not convert .psd files that are already committed as regular blobs. That is the job of git lfs migrate, which a later chapter covers.
Listing managed files with `git lfs ls-files`
git lfs ls-files reads the Git index and shows each file that is stored as an LFS pointer.
4d7a214614 * design/logo.psd
9b1f0c77aa - textures/wall.pngEach line has three parts:
- A short form of the object ID, which is the SHA-256 of the real content.
- A marker character.
- The path of the file.
The marker is the useful part:
| Marker | Meaning |
|---|---|
| `*` | The real file content is present in your working tree. |
| `-` | Only the pointer is present. The content has not been downloaded or checked out. |
A - is normal after a partial clone, and it is also the symptom of a failed download. Seeing it by itself tells you nothing about whether something is broken. What matters is whether you expected that file to be present.
Useful options
| Command | Output |
|---|---|
| `git lfs ls-files --long` | Shows the full 64-character object ID instead of the short form. |
| `git lfs ls-files --size` | Adds the size of each file in a readable unit. |
| `git lfs ls-files --name-only` | Prints only paths, which is handy in scripts. |
| `git lfs ls-files --all` | Lists files from every reachable commit, not just the current one. |
| `git lfs ls-files main` | Lists files as of a given ref. |
You can combine them. This prints the size and the full ID for every LFS file at the current commit:
git lfs ls-files --long --sizeIf you only need to find the biggest files, pipe through standard tools:
git lfs ls-files --size | sort -t'(' -k2 -h | tail -n 5The exact column layout can vary between versions of Git LFS, so test a sorting command like this one on your own output before you rely on it in a script. For anything automated, --name-only is the stable choice.
What `ls-files` does not show
git lfs ls-files reports what the index and commits say. It lists a file when the pointer is committed or staged. A file that matches a tracked pattern but was committed before tracking began is not listed, because it is a regular blob. If you expected a file in the list and it is missing, check that it was added after the pattern existed.
Reading working-tree state with `git lfs status`
git lfs status is the LFS equivalent of git status. It groups changes into three sections.
On branch main
Objects to be pushed to origin/main:
Git LFS objects to be committed:
design/logo.psd (LFS: 4d7a214614)
Git LFS objects not staged for commit:
textures/wall.png (File: 9b1f0c77aa -> LFS: 51ac03e9d2)The sections mean:
- Objects to be pushed: commits that reference LFS objects the remote does not have yet. This is the section to check before
git push. - Git LFS objects to be committed: files staged as pointers.
- Git LFS objects not staged for commit: files changed in the working tree but not yet staged.
The arrow notation File: X -> LFS: Y is a warning sign worth understanding. It means that the version Git has stored for that path, shown as File, is a regular blob, while the version in your working tree would become an LFS pointer. This happens when you track a pattern for files that already exist in the repository. The next commit will change the file from a regular blob to a pointer.
Use git lfs status --porcelain for a machine-readable form, similar to git status --porcelain.
Checking a single pointer
You can look at the pointer for a file straight from Git, without any LFS command:
git show HEAD:design/logo.psdIf the file is stored through LFS, the output is the three-line pointer:
version https://git-lfs.github.com/spec/v1
oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393
size 12345If you see real binary content instead, that commit stored the file as a regular blob. This is the quickest way to confirm which side of a migration a given commit is on.
To print a pointer for a file in your working tree without committing, use:
git lfs pointer --file=design/logo.psdTo compare it against what is stored, run git lfs pointer --check --file=design/logo.psd. It exits with a status that tells you whether the file is a valid pointer, which scripts can use.
Confirming that the filter is active
If tracked files never show up in ls-files, the filter may not be configured on your machine. Check the configuration:
git config --get-regexp filter.lfs
git lfs envgit lfs env prints the Git LFS version, the endpoint URL it will talk to, and the local storage path. Open it first when you need to report a problem, since it holds most of what a maintainer asks for.
If filter.lfs.clean is missing, run git lfs install once. That sets up the filters for your user, as covered in the installation chapter.
A diagnostic flow
The commands fit together as a sequence. This diagram shows which one to reach for.
Worked example
Suppose you cloned a repository and a teammate says the texture file will not open in your editor. Work through it in order.
- Check whether LFS knows about the file:
``bash git lfs ls-files --name-only | grep wall.png ``
- Look at the marker with
git lfs ls-files. If it shows-, the content was not downloaded.
- Confirm the working tree file is a pointer by reading its first line:
``bash head -n 1 textures/wall.png ``
The output version https://git-lfs.github.com/spec/v1 confirms it.
- Download the content and check again:
``bash git lfs pull --include="textures/wall.png" git lfs ls-files | grep wall.png ``
The marker should now be *. If the pull fails, git lfs env shows which endpoint it tried to reach, which narrows the problem to the server or to your credentials.
Common mistakes
- Trusting
git statusalone. It shows a modified file but not whether the upload will succeed. Usegit lfs statusbefore pushing. - Expecting
ls-filesto list files that match a pattern but were committed earlier. Only files stored as pointers appear. - Reading
-as an error. It can be intended, for example afterGIT_LFS_SKIP_SMUDGE=1or an--includefilter. - Assuming a short object ID is unique forever. The short form is a prefix for display. Use
--longwhen you compare IDs between systems.
Summary
Use git lfs track for the rules, git lfs ls-files for the files and whether their content is present, git lfs status for pending changes, and git lfs env for configuration and endpoints. A - in ls-files means only the pointer is local. An arrow in status means the file is switching from a regular blob to a pointer.
Exercise
After a fresh clone, git lfs ls-files shows - next to textures/wall.png. What does the marker mean, and which command downloads the real content for only that file?
Show answer
The - means the working tree holds only the pointer file, so the content has not been downloaded or checked out. Run git lfs pull --include="textures/wall.png" to fetch and check out that single file. git lfs ls-files then shows * for it.
Exercise
You add *.png to LFS tracking in a repository that already has committed PNG files. git lfs status shows lines like File: 9b1f0c77aa -> LFS: 51ac03e9d2. What does this tell you, and does git lfs ls-files list those older PNGs as managed files before you commit?
Show answer
The arrow means the stored version of the path is a regular blob, while the working-tree version would be committed as an LFS pointer, so the next commit converts it. Before that commit, git lfs ls-files does not list those PNGs as pointers, because the existing commits hold regular blobs. To convert the history as well, use git lfs migrate import.