Skip to content

Home

Purge a file from history

Completely purges a file from history.

❗️ Caution

This is a destructive action that rewrites the history of the entire repository. Make sure you know what you are doing.

git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch <path>" \
  --prune-empty --tag-name-filter cat -- --all
git push <remote> --force --all

# Examples
git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch config/apiKeys.json" \
  --prune-empty --tag-name-filter cat -- --all
# Purges `config/apiKeys.json` from history
git push origin --force --all
# Force pushes the changes to the remote repository

More like this

Start typing a keyphrase to see matching snippets.