ecain ecain - 29 days ago 7x
Git Question

Removing files from past commits in GitHub repository with BFG Repo-Cleaner

I have a file in my GitHub repository that I would like to remove from my previous commits. I used BFG Repo-Cleaner's

command and it appeared to work, but when I go on my GitHub repository the file is still on all the previous commits. If I try and do the command again, it gives me a

BFG aborting: No refs to update - no dirty commits found??

Am I misunderstanding how BFG works? If so how can I remove the file from my past commits on GitHub?

Here are the steps I took:

  1. Cloned a copy of my GitHub repo into a local folder using the

  2. I then
    to my local visual studio project.

  3. I then entered in the command
    java -jar bfg- --delete-files <.json file I wanted to delete> <my local clone copy from step 1>.git

  4. I then entered in
    git reflog expire --expire=now --all && git gc --prune=now --aggressive

  5. Ran
    git push


A git push alone should not work, since BFG repo cleaner does rewrite the history of a repo.

It should work though when you cloned (as you did) with --mirror, since, on git push, locally updated refs will be force updated on the remote end.

Note that:

By default the HEAD branch is protected, and while its history will be cleaned, the very latest commit (the 'tip') is a protected commit and its file-hierarchy won't be changed at all.

Don't forget to remove your file from your HEAD (current working tree) as well, before pushing back.

After discussion, it seems the commands were not executed in the right folder. That folder should end with .git: xxx.git: a clone --mirror is a bare repo.