2

In my company, we store system development related files with git LFS. This repository contains CAD data, images, documents (*.pdf, *.docx, *.xlsx) and so on. There is absolute necessity to have all files under version control. However, the way the repository was used ended up blowing the repository up to a total size of 8GB, despite all files being tracked by LFS.

Basically everything was pushed onto the master branch, which seems making the LFS storage obsolete, as nothing can be pruned to save local storage.

Question

Is there a way to allow more local objects to be pruned retroactively?

AnsFourtyTwo
  • 2,480
  • 2
  • 13
  • 33

1 Answers1

4

You can use the below command

git lfs prune

From docs,

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
  • a 'recent branch'; see [RECENT FILES]
  • a 'recent commit' on the current branch or recent branches; see [RECENT FILES]
  • a commit which has not been pushed; see [UNPUSHED LFS FILES]
  • any other worktree checkouts; see git-worktree(1)

In general terms, prune will delete files you're not currently using and which are not 'recent', so long as they've been pushed i.e. the local copy is not the only one.

The reflog is not considered, only commits. Therefore LFS objects that are only referenced by orphaned commits are always deleted.

Note: you should not run git lfs prune if you have different repositories sharing the same custom storage directory; see git-lfs-config(1) for more details about lfs.storage option.


Since you are unable to prune due to the LFS tracked files being referenced by the current checkout, you can clone the local repo without the LFS tracked files using the GIT_LFS_SKIP_SMUDGE setting

export GIT_LFS_SKIP_SMUDGE=1
git clone /path/to/local/repo test

This should reduce the size of the repo as the LFS tracked files will be converted to pointer files. If you want to use the LFS tracked files you need to do a git lfs pull.

Since git lfs pull will download all the LFS tracked files in the current checkout, you can use the inclusion and exclusion options to either include or exclude particular files.

For example you can include all pdfs (LFS tracked files) in the repo by

git lfs pull -I "*.pdf"

or exclude them by

git lfs pull -X "*.pdf"

Note that you can clone from the remote repo itself, the cloning of local repo to test repo is just an example to show that the size reduced.

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
  • Thank you, but I am aware of the documentation. As I have written, everything is on `master`, so the current checkout, making the LFS redundant. – AnsFourtyTwo Jan 10 '20 at 12:49
  • By _everything on `master`_, does it also include LFS tracked files ? I am confused why LFS is redundant, is it because the files which were supposed to be tracked by LFS have been pushed to master as normal files ? – Saurabh P Bhandari Jan 10 '20 at 13:01
  • _blowing the repository up to a total size of 8GB, despite all files being tracked by LFS_, you can confirm if LFS files are causing the increase in size by checking the size of `.git/lfs` directory and how much it is contributing to the total size of the repository (since your concern is with the local repository) – Saurabh P Bhandari Jan 10 '20 at 13:08
  • Yes, it means that all files are pushed to master, also the LFS track ones. And as no files get pruned as long as they are referenced by *the current checkout*, i will never be able to reduce local repository size. – AnsFourtyTwo Jan 10 '20 at 14:44
  • `.git/lfs` has a total size of 2GB. – AnsFourtyTwo Jan 10 '20 at 14:45
  • @SimonFink, you could reduce the size provided you currently don't want to work on the LFS files, you can convert the LFS files to their pointer format and checkout the individual LFS file when needed – Saurabh P Bhandari Jan 10 '20 at 14:49
  • Thanks! Running `git lfs prune` reduced the size of my `.git/lfs` folder from **158 GB** to **96 GB**, for a total savings of 62 GB! And, it took only 1.0 minutes to run! This is in a repo which is 80 GB in size, NOT counting the `.git/lfs` folder. – Gabriel Staples Jul 28 '21 at 04:10