2

The hard drives of our local machines fill up with large files that are stored in Git LFS but that are not currently checked out.

It would be convenient if everything that is not part of the current commit was only stored at the server and downloaded as needed if a commit "exposes" them.

Is this possible using some configuration or are there any other Git extensions that could help?

Edit: A similar question suggests using git lfs prune. That doesn't do what I want since the files I wish removed from the local computer are not deleted. They are just not visible in the current commit.

  • Possible duplicate of [git lfs "objects" taking a lot of disk space](https://stackoverflow.com/questions/34892478/git-lfs-objects-taking-a-lot-of-disk-space) – Nils Werner Dec 22 '17 at 08:36
  • Your last statement confuses me. The files not present in the current commit should not be there, no matter if you use `git lfs prune` or not. Also, have you tried playing around with `lfs.pruneoffsetdays`? – Nils Werner Dec 22 '17 at 10:48
  • What I mean is that if I have a 100MB file that is checked in. Then I modify and check in a new version, also 100MB. The total size of the repo (locally on disk) is now 200MB even though only the latest version of the file is "visible" when I have the latest commit checked out. I would like that a `git checkout HEAD^` removed this new version and downloaded the old one. – Anders Sundman Dec 22 '17 at 11:33
  • Sorry about the confusion! The lfs prune solution works fine. I messed up in how I got the directory size. Resolved. Thanks! – Anders Sundman Dec 22 '17 at 11:47
  • The lfs.pruneoffsetdays 0 works fine. Would be really helpful if you could update the original question with that as a comment or answer. Adding it to a git post-checkout hook makes it even more convenient. – Anders Sundman Dec 22 '17 at 12:06

1 Answers1

2

You can prune all LFS files that are not part of the currently checked out commit by setting

git config lfs.pruneoffsetdays 0

once, and then running

git lfs prune

every time you want to shrink your repository. To routinely prune LFS objects, you can add the command to the pre-auto-gc hook.

Nils Werner
  • 34,832
  • 7
  • 76
  • 98