Sub topic 6
Inspecting what LFS is managing
This chapter assumes you can clone, commit, and push with Git, and that you have already run git lfs install and tracked a pattern such as *.psd. Here you learn to check what LFS is actually doing, so you can tell whether a file is stored as a pointer or as real content.
Why inspect
Tracking a pattern does not guarantee a file went through LFS. A file committed before the pattern existed is stored as a normal Git blob. A pattern with a typo matches nothing. Three commands answer most questions.
Listing managed files with git lfs ls-files
git lfs ls-files lists the files in the current commit that LFS manages.
git lfs ls-filesEach line shows a short object ID, a marker, and a path:
4d7a214614 * design/logo.psd
9b1c0e77a2 - textures/wall.pngThe marker tells you whether the content is on disk:
*means the real file content is present in your working tree.-means only the pointer file is present. The content has not been downloaded.
The ID is the first characters of the SHA-256 oid that appears in the pointer file. If a large file you expect is missing from this list, it is stored as a regular Git blob.
Checking pending changes with git lfs status
git lfs status is similar to git status, but it reports how LFS will treat changes.
git lfs statusThe output groups files into sections:
- Objects to be pushed: LFS objects in local commits that the remote does not have yet.
- Objects to be committed: staged files, shown as either
LFS(will be stored as a pointer) orGit(will be stored as a normal blob). - Objects not staged for commit: modified files that are not staged yet.
The Git label on a staged binary is a warning sign. It means the file does not match any tracked pattern, so it will go into regular history.
Viewing tracked patterns with git lfs track
Run git lfs track with no arguments to print the patterns recorded in .gitattributes.
git lfs trackListing tracking patterns
*.psd (.gitattributes)If your file name is not matched by any listed pattern, LFS will not handle it.
Reading the pointer yourself
The pointer is a small text file stored in the Git commit. You can print it directly with git cat-file, which reads what Git actually stored instead of what the LFS filter shows you:
git cat-file -p HEAD:design/logo.psdversion https://git-lfs.github.com/spec/v1
oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393
size 12345If this prints a few lines like the above, the file is in LFS. If it prints binary garbage, it was committed as a regular blob.
A typical check
The diagram below shows the order that works well before you push.
git add --renormalize <path> re-applies the filters to a file that is already tracked by Git, which is how you fix a file that was staged before its pattern existed.
Common errors
| Symptom | Likely cause | Check |
|---|---|---|
| `git lfs ls-files` is empty | No file has been committed through LFS yet | `git lfs track` and `git lfs status` |
| Staged file labelled `Git` | Pattern missing, misspelled, or `.gitattributes` not staged | `git lfs track` |
| `-` marker on a file you need | Content was not downloaded | `git lfs pull` |
| Pointer text appears when you open a file | Smudge filter did not run | `git lfs install`, then `git lfs pull` |
Exercise
You staged art/hero.psd and git lfs status lists it under "Objects to be committed" with the label Git. What does that tell you, and what do you check first?
Show answer
The file will be stored as a regular Git blob, not as an LFS pointer, because no tracking pattern matches it. Run git lfs track to see the active patterns. Add or correct the pattern so it matches the path, stage .gitattributes, and run git add --renormalize art/hero.psd. Then run git lfs status again and confirm the label is LFS.