Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a protected commit using BFG

When cleaning the repo with BFG (https://rtyley.github.io/bfg-repo-cleaner/) ,encountered the following :

Protected commits
-----------------

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

 * commit ******* (protected by 'HEAD')
like image 903
rcde0 Avatar asked Apr 05 '17 12:04

rcde0


People also ask

What is BFG repo cleaner?

BFG Repo cleaner is an alternative to git filter-branch. It can be used to remove sensitive data or large files that were committed wrongly like binaries compiled from the source. It is written in Scala. Project website: BFG Repo Cleaner.


3 Answers

Running BFG with: --no-blob-protection fixed it for me.

The docs are here: https://rtyley.github.io/bfg-repo-cleaner/, but I didn't see where they really call that out as a means to move past the error.

Note: In my case I had already tried to remove files manually, not using BFG, which got me in a state where I had to use --no-blob-protection.

like image 199
technocrat Avatar answered Oct 20 '22 17:10

technocrat


If you're going to use a tool as powerful as BFG, I'd strongly advise you to read its documentation (which spells this out), but to answer your question:

BFG by default leaves "current" commits unchanged. Its author believes the only safe workflow is to clean up your repo's current state manually, test that everything still works, then use BFG to clean up history while leaving the current-state (which you already fixed manually) alone.

There are options available to change the protection from default (or turn it off) if you have use cases where you think it's unnecessary (as I have more often than not); but if you want to use those, you definitely need to read the docs.

like image 29
Mark Adelsberger Avatar answered Oct 20 '22 16:10

Mark Adelsberger


This is a very late reply, but I hit a similar problem.

Were you trying to remove a file from a git repo and its history? Were you in a hurry and failed to notice that file is present in the state of the most recent commit, which BFG by default treats as protected? This was an error that happened between my keyboard and chair today.

If you want to clean a repo: (1) remove the unwanted file with the usual git commands e.g., git rm file; git commit, (2) test that everything still works without that file, (3) use bfg to rewrite the repo history without that file.

like image 3
chrisinmtown Avatar answered Oct 20 '22 16:10

chrisinmtown