Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing missing LFS objects from git repository

I am missing a bunch of LFS objects in my git repository*, both on the clients and the server. I am aware that those objects are lost and that's okay. Unfortunately this means that git lfs fetch --all or even git lfs push --all origin will fail.

I would like to purge the "broken pointers" from the repository, either by replacing the binary with a dummy text file or by removing the pointer altogether. I am also aware that this involves rewriting history and that's also fine.

What would be the best way to proceed?

*To clarify, I am missing some LFS files on the server but not all of them and not for all revisions of those files.

For example, I have foo.png that has been modified in 3 commits:

  • foo.png (Version 1, LFS Sha: 03cfd743)
  • foo.png (Version 2, LFS Sha: 661f0797)
  • foo.png (Version 3, LFS Sha: 5fa2f122)

The LFS server no longer has foo.png version 2, so I would like to remove that commit from history. Unfortunately git lfs does not tell me which commit is broken, it simply tells me that 661f0797 is missing.

(For the record, I have found the missing files so I no longer have this issue but the solution should still be interesting!)

like image 223
Nepoxx Avatar asked Apr 04 '19 00:04

Nepoxx


People also ask

Where are LFS objects stored?

Git LFS objects can be large in size. By default, they are stored on the server GitLab is installed on.

What is git LFS prune?

DESCRIPTION. Deletes local copies of LFS files which are old, thus freeing up disk space. Prune operates by enumerating all the locally stored objects, and then deleting any which are not referenced by at least ONE of the following: ○ the current checkout.

Does git LFS Store history?

You should use Git LFS if you have large files or binary files to store in Git repositories. That's because Git is decentralized. So, every developer has the full change history on their computer.


1 Answers

if you're still looking for a way to see what commit is affected, get the missing LFS object ID and use this command to find the commit:

git log --source --all -p  -S <LFS-OBJ-ID>
like image 63
Valentin Dumitru Avatar answered Oct 22 '22 22:10

Valentin Dumitru