Skip to main content

Selectively cleaning git history

This way we clean any unwanted commits from the git history.

Requires: Java, bfg-repo-cleaner

  1. First create a local copy of the repo folder (as backup just in case)

  2. Clone a mirror of the git repo to a new location.

    git clone --mirror git@github.com:gqc/IoT_Arduino_to_ESP-IDF.git
  3. Clean up the repo as desired.
    In my case, I wanted to clean a build directory that was uploaded in an earlier commit.
    Check this for more usage commands.

    java -jar bfg-1.14.0.jar --delete-folders build IoT_Arduino_to_ESP-IDF.git
  4. Go into the repo directory and commit the changes

    cd IoT_Arduino_to_ESP-IDF.git

    git reflog expire --expire=now --all && git gc --prune=now --aggressive
  5. Push the changes to github

    git push
  6. Delete the mirror and the old repo you had. Clone a fresh copy of the repo from github. Make sure to compare with the backup you created in the step 1 and that haven't missed any important files in the cleaning step.