With Git LFS, why does running `git lfs track "*.psd"` after a year of committing PSDs straight into Git leave clones just as large?
answer
- tracking looks forward, not back
- filters run when content is added
- old blobs stay reachable
- renormalize fixes the tip only
- history needs migrate import
basics
~20 sTracking only changes how content is cleaned from now on; every PSD committed during that year is still a full blob reachable from history. Shrinking clones needs git lfs migrate import over all refs, which rewrites history.
solid answer
~50 s`git lfs track` only writes a `filter=lfs` line to `.gitattributes`; the clean filter runs when content is *added*, so nothing already committed changes. The PSDs in the working tree stay plain blobs until they are re-added — `git add --renormalize .` and a commit convert the tip — and every older version is still a full Git object reachable from every branch and tag, so a clone downloads all of them. Run `git lfs migrate info --everything` to see what the history holds, then `git lfs migrate import --everything --include="*.psd,*.fbx"` to rewrite every commit so the files become pointers from their first appearance. That shrinks the history but changes every affected commit ID and needs a force push. Tracking without either step leaves files marked LFS but stored as Git blobs, which show as permanently modified.
go deeper
Recall that tracking only applies to files added after the pattern exists; files already in history stay as they were.
Explain the three states — tracked but unconverted, converted at the tip with renormalize, converted in history with migrate import — and what each does to clone size.
Size the history with migrate info --everything first, then choose between a rewrite that shrinks clones and a no-rewrite commit that leaves history alone.
Weigh the one-off cost of rewriting shared history against carrying a year of binary blobs in every clone and mirror indefinitely.
## The setup that goes wrong A game studio's artists commit layered image (`.psd`) and 3D model (`.fbx`) files straight into Git for a year. The repository grows to many gigabytes and clones crawl, so the team adopts **Git LFS**: someone runs `git lfs track "*.psd" "*.fbx"`, commits `.gitattributes` and pushes. A week later fresh clones are exactly as large as before. Nothing is broken — this is how tracking works. ## Why tracking only looks forward `git lfs track` does one thing: it writes lines such as `*.psd filter=lfs diff=lfs merge=lfs -text` into `.gitattributes`. That attribute tells Git to run Git LFS's **clean** filter when matching content is **added** to the index, and the **smudge** filter when it is checked out. Neither filter touches what is already committed: - Every PSD and FBX committed during that year is a **full Git blob**, referenced by commits that are themselves referenced by branches and tags. - Git downloads every reachable object on a normal clone, so all of those blobs still travel with every clone. - Even the copies in the current working tree are still stored as blobs at the tip until someone re-adds them. So there are really three different states a file can be in, and only one of them shrinks clones: | State | How you get there | Tip stores | History stores | Clone size | |---|---|---|---|---| | Tracked, not converted | `git lfs track` only | Full blob | Full blobs | Unchanged | | Converted at the tip | `git add --renormalize .` + commit, or `git lfs migrate import --no-rewrite` | Pointer | Full blobs | Barely changes | | Converted in history | `git lfs migrate import --everything --include=...` | Pointer | Pointers | Shrinks | ## The half-converted trap The first state is worse than it looks. The attributes now say every PSD should be a pointer, but the committed content is not one. The Git LFS FAQ describes the result: such files **show as modified permanently**, and `git reset --hard` does not help because Git checks the file out and immediately sees it as different again. Checkouts may also warn `Encountered 1 file that should have been a pointer, but wasn't`. The fix the FAQ gives for the tip is, on an otherwise clean tree: ```bash $ git add --renormalize . $ git commit -m "Store tracked PSD and FBX files in Git LFS" ``` This has to be done on every branch that carries the files. It stops the noise and makes future versions small, but it leaves every older version in history as a full blob. ## Converting the history To actually shrink clones, the old blobs must stop being reachable, which means rewriting the commits that contain them. `git lfs migrate` has three modes: 1. **`info`** — reports, by file extension, how many files and how many bytes the history holds. By default it covers only the current branch and only commits no remote has yet; `--everything` covers commits reachable from all local and remote refs. `--above=<size>` counts only files above a size, `--top=<n>` shows more than the default five rows. 2. **`import`** — rewrites commits so that matching files become pointers from the point where each type first appears, and adds the matching `.gitattributes` entries along the way, as if `git lfs track` had been run back then. 3. **`export`** — the reverse: turns pointers back into plain Git blobs, for teams leaving Git LFS. It also rewrites history. For the studio, the sequence is: ```bash $ git lfs migrate info --everything $ git lfs migrate import --everything --include="*.psd,*.fbx" $ git lfs migrate info --everything ``` After checking the result, the rewritten branches have to be force-pushed, and every collaborator has to move onto the new history — the costs are covered in their own question. ## When history cannot be rewritten Some teams cannot rewrite shared history: too many clones, signed releases, or downstream forks. Then the choice is to convert the tip only and accept the existing size: - `git add --renormalize .` after tracking, then commit. - `git lfs migrate import --no-rewrite --yes <files>` — converts the listed files, which must already match tracked patterns, in **one new commit** on the current branch; existing commits keep their IDs. Both stop the repository growing further in binary blobs, and neither removes the year already committed. Removing old blobs by other history-rewriting tools is a general Git subject; with Git LFS, `migrate import` is the tool built for the job because it also writes the pointers and the `.gitattributes` entries.
- What does `git add --renormalize .` achieve after `git lfs track`, and what does it not?It re-runs every tracked file in the working tree through the clean filter, so the next commit stores pointers for the PSDs and FBXs at the tip. It does not touch earlier commits: every old version remains a full Git blob, so clone size barely changes.
- How do you see how much of the history is PSD and FBX before rewriting anything?`git lfs migrate info --everything` summarises file types by total size and count across all local and remote refs; without `--everything` it only covers the current branch's unpushed commits. `--above=<size>` narrows to large files and `--top=<n>` shows more than the default five rows.
- What does `git lfs migrate import --no-rewrite` do in this situation?It converts the files you list, which must already match tracked patterns, in one new commit on the current branch, without changing existing commits. That is the safe choice when history cannot be rewritten, but it does not shrink clones: the old blobs stay in history.
- git lfs track converts every past version of matching files to pointers.
- Committing the .gitattributes change is enough to shrink the repository.
- Deleting the PSDs in a new commit removes them from clones.
- git lfs migrate import --no-rewrite shrinks the existing history.
- A plain git lfs migrate import with no ref options covers commits already pushed.