Git LFS pointer instead of a PNG? Check the file your CI build actually reads

2026-12-01来源 dev.toEnglish
Git LFS pointer instead of a PNG? Check the file your CI build actually reads

assets/banner.png exists. Git reports a clean checkout. The image decoder still rejects it. Before touching your rendering code, check whether the file contains a PNG or a Git LFS pointer with a .png filename.

Git has the reference; LFS has the bytes

Git LFS stores a small text pointer in the commit and keeps the original content separately. A checkout needs to replace the pointer with the binary file before a build can read that asset.

A Git commit stores a pointer that refers to separate PNG bytes in the LFS store.

Start with the same path your build reads. A filename tells you nothing about its contents. If file reports ASCII text and the filter is lfs, check the pointer before blaming your decoder.

file assets/banner.png git check-attr filter -- assets/banner.png 

Use the file command to distinguish ASCII pointer text from real PNG data.

In a disposable local repository, a checkout with GIT_LFS_SKIP_SMUDGE=1 preserved the pointer at the exact path. A small release preview then left the banner area empty because the decoder could not read it. This is the actual rendered preview from the local lab, not an image of a GitHub-hosted runner.

Actual local preview render with an empty banner area after a pointer-only checkout.

The text begins with version https://git-lfs.github.com/spec/v1. The next lines identify the binary by SHA-256 and report its intended size. In the lab the size line said 5,198 bytes; it describes the full PNG, not the much shorter pointer on disk.

The actual pointer has version, SHA-256 object ID and expected binary size fields.

Fetch the object before rendering

On GitHub Actions, enable the lfs input on your checkout step when the job needs the repository's LFS files. The checkout action documentation lists that input as off by default.

steps: - uses: actions/checkout@v6 with: lfs: true 

For a narrower local fetch, run this from the checkout with Git LFS available and access to the repository's LFS objects:

git lfs pull --include='assets/banner.png' --exclude='' 

The checkout input is convenient when the build uses many files; the targeted command was enough for this one banner. Fetch the assets for the job that reads them, rather than assuming a different job populated this job's checkout.

Two separate ways to obtain Git LFS objects: the checkout input or a selective pull.

After that pull against the same disposable local remote, file reported a 680 × 300 PNG. Rerunning the same preview rendered the banner from the file at the same path.

Actual local preview after git lfs pull, showing the restored release-status banner.

There's a quick way to see that the commit itself did not change: inspect its recorded blob with git cat-file blob HEAD:assets/banner.png. In the experiment it still contained the original pointer, but the SHA-256 of the working file matched the object ID. A clean working tree by itself did not tell those two states apart.

The Git object remains a pointer both times, while the checked-out file changes into a 680 by 300 PNG.

Fail at the input, not at the end of the build

If PNG is a hard requirement, check its eight-byte signature first. Use a decoder too if the release already has one available. The signature catches the text pointer; an actual read checks more than the first few bytes.

from pathlib import Path from PIL import Image asset = Path("assets/banner.png") with asset.open("rb") as source: if source.read(8) != b"\x89PNG\r\n\x1a\n": raise SystemExit(f"{asset}: expected PNG; inspect the checkout for an LFS pointer") with Image.open(asset) as image: image.verify() 

A two-step preflight checks the PNG signature and then verifies the file with Pillow.

If pulling still leaves text, save the fetch error and check access to the LFS object or any reported quota problem. Do not publish a build artifact that quietly dropped an image. The useful distinction is which step failed: resolving the tracked object, or decoding binary data that actually arrived.

If the file still fails the check, investigate the fetch before rerunning the build.

Sources: Git LFS pointer specification, git lfs pull manual, and actions/checkout. Visuals: original diagrams and two actual renders from a disposable Git 2.56.1 / Git LFS 3.6.1 local reproduction, with a synthetic banner. The GitHub Actions snippet illustrates the documented input; the lab did not run on GitHub.

Disclosure: This article was prepared using a fully autonomous AI workflow. The local Git LFS reproduction and PNG checks were executed and the results reviewed.

原文:https://www.a8q9.cn/en/article/git-lfs-pointer-instead-of-a-png-check-the-file-your-ci-build-actually-reads-e132a7.html

相关文章