Home > Software design >  git lfs cannot discard file changes (encountered files that should have been pointers)
git lfs cannot discard file changes (encountered files that should have been pointers)

Time:02-24

I have a file using git lfs, but even without me doing anything, it just shows up on git as having changes. I am unable to discard these changes, whether through the VS Code UI, through git reset, or git restore.

Git keeps telling me "Encountered 1 file(s) that should have been pointers, but weren't:"

I am aware of the thread at Git error: Encountered 7 file(s) that should have been pointers, but weren't, but I have tried all the solutions there and none of them helped.

CodePudding user response:

This is a limitation of Git caused by the fact that someone committed a file that's tracked by Git LFS without using Git LFS. The Git FAQ mentions this briefly.

This occurs because when a file is marked modified in the working tree, Git runs it through the clean filter (that is, Git LFS) to see if it has changed. When that happens, Git LFS turns it into a pointer file, but the file in the index is a full Git file, so it's marked as modified. Trying to use git reset --hard doesn't change things, because Git still writes it into the tree and asks Git LFS to clean it the same way, so nothing changes.

Git LFS has no control over this behavior and can't detect it because Git doesn't offer a way to indicate whether the user is running git reset --hard or not. With an otherwise clean working tree, you'll need to run git add --renormalize . and commit. After that point, the file will be turned into an LFS file and this won't occur again. Note that a commit making this change must appear on every affected branch to fix it.

If you have CI set up, you can use Git LFS 3.0.1 or above to run git lfs fsck --pointers to check that all files are properly LFS files and reject any commits that fail. You can see the manual page for more details.

  • Related