Discard changes that cannot be discarded in git


Sometimes you may encounter an issue in, for example, GitHub Desktop where you cannot discard certain changes, even after multiple attempts and even after restarting GitHub Desktop or your computer.

If you try to remove those files using the command line, you will most likely see an error like this:

Encountered <X> file(s) that should have been pointers, but weren't:

This usually happens because of Git LFS (Large File Storage).

Git LFS replaces large files (such as 3d models, textures, or audio) with lightweight “pointer files” inside your repository. These pointers tell Git where the real content is stored. If something goes wrong during syncing, cloning, or discarding, Git may end up with the actual file contents instead of the expected pointer files. When that happens, Git cannot properly discard the changes, since it detects that the file is in an invalid state — it should have been a pointer, but it isn’t.

The fix is straightforward: run the following commands in your terminal (either one by one in order, or by copying and pasting the entire block at once). These commands reset the problematic files back to their proper pointer state, allowing GitHub Desktop (or any other git client) to work with them normally again:

Terminal window
git rm --cached -r .
git reset --hard
git reset .
git checkout .

If the issue persists after running the commands above, you may need to re-fetch the LFS objects and then repeat the reset. Run the following:

Terminal window
git lfs fetch
git lfs checkout

Then run the reset again:

Terminal window
git rm --cached -r .
git reset --hard

This ensures that the actual large file contents are properly downloaded by LFS, and then the reset forces Git to re-checkout everything in its correct pointer state.