How to remove files from the commit history in Bitbucket Cloud


 

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

   

Summary

This article can be used to remove the unwanted files from the commit history.

Solution

Please keep in mind that this step-by-step uses BFG Repo Cleaner as a tool to rewrite the repository's history.

(warning) Just a heads up, you will need to install a Java Development kit to run the BFG installer.

  1. Clone bare repository on the machine

    $ git clone --mirror <RepoURL>
  2.  Check the names of the files by the commit's hash

    $ git show --pretty="" --name-only  <HashID>
  3.  Run the BFG to clear your repo's history (Remember to create a backup first, just for reassurance). This command should be executed from outside of the repository

    $ java -jar bfg.jar --delete-files <FileName> <repoName>
  4.  Run a GC to clean all the dangling commits left by the BFG

    $ cd repoName
    $ git reflog expire --expire=now --all && git gc --prune=now --aggressive
  5.  If you are happy with the results, just push the changes

    $ git push --force


Please make sure to contact our support through https://support.atlassian.com/contact/ to run the Garbage Collection on the server-side repository and get rid of the unwanted commit.


Last modified on Jun 22, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.