Search code examples
gitbitbucketbfg-repo-cleaner

Git/Bitbucket - Remove file from entire history/commits


Following the directions for BFG I proceeded to remove a private file that should not be on the repo/commit history.

https://rtyley.github.io/bfg-repo-cleaner/

I ran

$ bfg --delete-files .private  my-repo.git

and pushed the changes however, it caused me to merge the master branch and the file still shows, the code is in the .private file and all commits are still in the history.

How can I remove .private from the entire repo's commit history etc?


Solution

  • You will have to force push. When you're removing a file from history you're creating new commits and a new history tree. It won't have the current master as an ancestor, so you'll need to either merge or force push. If you merge, as you noticed, the file will be back. So you need to force push.

    Also, anybody who uses the repo needs to be aware not to merge their master back into there, or the file will "be back".