3

git clone --filter=blob:none allows me to quickly clone a repo, without having to download gigabytes of objects. The repo size is small, as expected, because git cloned just the latest blobs at that point in time. Say, I work with this repo, switch branches, compare, etc. Git will download objects as and when needed. Now, the size of my repo is again increasing, locally, because of all of the downloaded objects. Is there a way to delete all of the local blobs and retain just the latest blob? In other words, is there a way to reach the same kind of state when I first cloned the repo using the partial clone with all commits, trees, but only the latest blob?

P.S. I know I can clone a fresh partial repo again. But I want to know if something is possible without having to clone again.

3
  • 1
    I am not looking to modify the history in any way. I am just trying to reduce the size of the repo locally. Commented Dec 6, 2021 at 4:39
  • 1
    No, Git's support for this sort of thing is pretty primitive right now and the only way to shrink is to reclone.
    – torek
    Commented Dec 6, 2021 at 4:42
  • Excellent question! I wonder if one can just delete the largest blobs locally? Surely there must be a way to delete blobs with a filter. Commented May 19, 2023 at 0:45

1 Answer 1

1

This functionality is not directly supported by Git. However, you can use git gc or the more recent (Git 2.30+) git maintenance to decrease the repo size.

git maintenance run --task gc
git maintenance run --task loose-objects --task incremental-repack

This won't be the same as re-cloning the repo, but it should result in a smaller repo.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.