While making my most recent commit to my blog, I discovered (after the fact) that Iโ€™d accidentally committed a screenshot from a customer project, into my /images/ subdirectory.

While not a big deal (not as if it was a password file!), itโ€™s still an embarrassing bungle, so I wanted to purge it from my git repo and all previous commits.

Some research led me to The BFG, a java-based repo-scrubbing tool, which saved me from embarassment.

First, I downloaded the latest version of BFG, then I made a โ€œbareโ€ clone of my repo (bare = the git data but not the actual files).

I ran java -jar bfg-1.13.0.jar --delete-files "Screenshot at Oct 05 15-58-30.png" www.funkypenguin.co.nz.git against my bare repo, but stumbled on this issue:

Protected commits

These are your protected commits, and so their contents will NOT be altered:

 * commit fdc05636 (protected by 'HEAD') - contains 1 dirty file :
	- images/Screenshot at Oct 05 15-58-30.png (410.1 KB)

WARNING: The dirty content above may be removed from other commits, but as
the *protected* commits still use it, it will STILL exist in your repository.

Details of protected dirty content have been recorded here :


If you *really* want this content gone, make a manual commit that removes it,
and then run the BFG on a fresh copy of your repo.

BFG warned me that I couldnโ€™t delete any files in a protected commit (i.e. HEAD), so I made a dummy commit to move HEAD on from the commit including the screenshot, re-bare-cloned the repo, and tried again. This time, success:

Deleted files

	Filename                            Git id
	Screenshot at Oct 05 15-58-30.png | b44c3154 (410.1 KB)

In total, 8 object ids were changed. Full details are logged here:


BFG run is complete! When ready, run: git reflog expire --expire=now --all && git gc --prune=now --aggressive

As instructed, I chdirโ€™d into my repo directory, and ran git reflog expire --expire=now --all && git gc --prune=now --aggressive to complete the purge.

Now the screenshot is gone, and scrubbed from my git repo history ?

Youโ€™ve successfully subscribed to ๐Ÿง‘โ€๐Ÿ’ป Funky Penguin
Welcome back! Youโ€™ve successfully signed in.
Great! Youโ€™ve successfully signed up.
Your link has expired
Success! Check your email for magic link to sign-in.