Git LFS files

How a file kept in Git LFS reads in a diff, how a file comes to be kept there, and what stops one going in as a regular file.

In a repository that uses Git LFS, the files it stores there carry a box before the staging control in the working copy, read as Stored in Git LFS, unless Git LFS is turned off in Settings.

In a diff

A changed Git LFS file: its storage, its size before and after, and content that is not on this Mac yet.

A Git LFS file has no lines to compare. Its diff shows where it is stored, its size before and after, and a preview when it is an image or a PDF. Content that is not on this Mac reads Not downloaded, with Download, for an older revision as well as the current one.

Such a file is staged whole: its diff offers no hunk or line to stage.

Storing a file in Git LFS

  • Track with Git LFS, in a changed file’s context menu, offers This File or every file with its extension, such as All .png Files.
  • Add Pattern, in the Git LFS section of the repository’s settings, takes any pattern. It is also how a repository starts using Git LFS.

Either one writes the pattern to .gitattributes, converts the committed files it matches, and stages both, so the next commit stores them in Git LFS.

A pattern’s bin, in the same section, removes it. Files already stored stay in Git LFS, and a pattern that committed files still use is kept.

Large files outside Git LFS

A changed file of 50 MB or more that is not in Git LFS gets a note under the commit message, with Track with Git LFS. The note says so when a remote is on GitHub and the file is over its 100 MB limit, which is the one case it shows while Git LFS is turned off.

A file staged as a regular file

A file Git LFS should store, staged as a regular file: Commit waits until it is stored in Git LFS.

Where Git LFS has never been set up, Git stages a file that the repository keeps in Git LFS as a regular file, without a word. Innesta checks what is staged: while such a file is there, Commit is unavailable, and Store in Git LFS stages it again through Git LFS.

Conflicts and discarded changes

Git cannot merge two versions of a Git LFS file line by line, so a conflict in one is resolved by choosing a side: Use Ours or Use Theirs, from the arrow beside Resolve….

Discarding a Git LFS file keeps its content with the backup, so restoring the change brings the file back.