Skip to content

Instantly share code, notes, and snippets.

@oscarychen
Last active September 30, 2021 17:25
Show Gist options
  • Save oscarychen/541e0100bb9a8fef2b09f6c4af928a52 to your computer and use it in GitHub Desktop.
Save oscarychen/541e0100bb9a8fef2b09f6c4af928a52 to your computer and use it in GitHub Desktop.
Remove files from git commit history

Removing files from Git commit history

Clone a fresh copy of the repository using ssh and --mirror flag git clone --mirror git://example.com/some-big-repo.git

Download the bfg.jar file from BFG Repo-cleaner

Run BFG on the repo: java -jar bfg.jar --delete-files "*.csv" some-big-repo.git

Enter the repo and run command:

cd some-big-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive

Now you can try force pushing into the repository, you may encounter error if you have merged pull request in commit history, if you do, try the following: git for-each-ref --format 'delete %(refname)' refs/pull | git update-ref --stdin

and then force push again: git push --force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment