Search code examples
gitgitlabgit-lfs

Deleted the LFS objects from GitLab repository however storage space still not freed up


I have a GitLab repository, and using the feature branch, remove-lfs I pushed some LFS objects after running these commands in the same order

git lfs install
git lfs track "lfs/*.mp4"
git add .

and then commit and push that I later deleted them (including .gitattributes file) with the below commands:-

git filter-repo --force --path lfs/ --invert-paths

My LFS files got deleted successfully from the Gitlab remote repository however the space occupied by LFS objects is still not freed up as shown in this screenshot below even after running below commands:-

git push --force --all origin
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push -u origin --tags -f

enter image description here

How to regain the space occupied by deleted LFS objects?


Solution

  • I followed these steps and it worked for me:-

    Install git-filter-repo first and follow the steps below to clear the unwanted LFS:-

    git filter-repo --force --path /lfs_dir --invert-paths
    

    assuming your LFS are inside the directory (/lfs_dir) or modify the above command to point to right directory of LFS that needs to be removed

    Then, remove the lines of unwanted LFS from .gitattributes file, and then execute following commands

    git add .
    git commit -m <commit message>
    git push --force --all origin
    git reflog expire --expire=now --all
    git gc --prune=now --aggressive
    

    Go to GitLab → Project Repository Settings → General → Advanced and click on ‘Prune unreachable objects’ to prune them now manually.