Skip to content

Instantly share code, notes, and snippets.

@j18e
Created November 14, 2019 14:55
Show Gist options
  • Save j18e/91cf4e1fae22e1e6e6600974289a1ef3 to your computer and use it in GitHub Desktop.
Save j18e/91cf4e1fae22e1e6e6600974289a1ef3 to your computer and use it in GitHub Desktop.
Remove file(s) from git history
#!/bin/bash -eu
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch src/images/my_large_photos_*.jpg' \
--prune-empty --tag-name-filter cat -- --all
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now --aggressive
# when all this is done, verify that everything looks good and run git push -f
# be sure to back up your repo beforehand!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment