How to find/identify large files/commits in Git history?

I’ve got a git repo of 300 MB. My currently checked-out files weigh 2 MB, and the git repo weighs 298 MB. This is basically a code-only repo that should not weigh more than a few MB.

Most likely, somebody at some point committed some heavy files by accident (video, huge images, etc), and then removed them…but not from git, so we have a history with useless large files. How can I track down the large files in the git history? There are 400+ commits, so going one by will be time-consuming.

There’s also a lazier solution now available, GitExtensions now has a plugin that does this in UI (and handles history rewrites as well).

Questions:

Answers:

🚀 A blazingly fast shell one-liner 🚀

This shell script displays all blob objects in the repository, sorted from smallest to largest.

For my sample repo, it ran about 100 times faster than the other ones found here.
On my trusty Athlon II X4 system, it handles the Linux Kernel repository with its 5.6 million objects in just over a minute.