#development #git

Let's have a look at some common Git LFS (large file storage) issues and how to fix them.

The issue that comes up most frequently is the following one:

1Encountered x file(s) that should have been pointers, but weren't

When you try to switch to a different branch or reset the current branch, the operation will fail and you will get an error similar to:

1$ git reset --hard HEAD
2HEAD is now at 901b26383 Start work for preparing container project.
3Encountered 2 file(s) that should have been pointers, but weren't:
4    testdata.zip
5    container.zip

The problem here is that the files indicated aren't checked in via LFS while the .gitattributes file (where you keep track of which file patterns are tracked via Git LFS) indicates that all .zip files are stored using Git LFS.

To fix the problem, the files need to be migrated to Git LFS. Migrate converts large Git objects to LFS pointers. The command to fix the errors is (which needs to be repeated for each file with this error):

1$ git lfs migrate import --yes --no-rewrite "testdata.zip"
2migrate: changes in your working copy will be overridden ...
3migrate: checkout: ..., done.                                                                       
1$ git lfs migrate import --yes --no-rewrite "container.zip"
2migrate: changes in your working copy will be overridden ...
3migrate: checkout: ..., done.                                                                       

After fixing the files, don't forget to push the changes back to the repository:

 1$ git push
 2Enumerating objects: 3, done.
 3Counting objects: 100% (3/3), done.
 4Delta compression using up to 12 threads
 5Compressing objects: 100% (3/3), done.
 6Writing objects: 100% (3/3), 574 bytes | 143.00 KiB/s, done.
 7Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
 8remote: Resolving deltas: 100% (1/1), done.
 9To https://github.com/pieterclaerhout/my-repo
10   0cdcb73ff..af31c0f64  develop -> develop

The above successfully converts pre-existing git objects to LFS objects. However, the regular objects still persist in the .git directory. These will be cleaned up eventually by git, but why not clean them up right away? To cleanup, you can run:

1$ git reflog expire --expire-unreachable=now --all
2$ git gc --prune=now

If you want to double-check which files are actually stored in Git LFS, you can use the git lfs ls-files command to get a list of all files which are stored with LFS:

1$ git lfs ls-files
2dad4c5t3y1 * testdata.zip
3d554b52b48 * container.zip

Another way of doing the same is using the git check-attr command:

$ git check-attr --all -- container.zip | grep "filter: lfs" 
container.zip: filter: lfs

If you want to learn more about Git LFS, you can consult the official website.