Skip to content

Instantly share code, notes, and snippets.

@wcarhart
Last active February 9, 2020 00:42
Show Gist options
  • Save wcarhart/719c56ad47c9ccb327666ab9150f6632 to your computer and use it in GitHub Desktop.
Save wcarhart/719c56ad47c9ccb327666ab9150f6632 to your computer and use it in GitHub Desktop.
Completely remove a file from Git history
# Completely remove a file from git history
# Remove file from all commits
# $path_to_file supports wildcards: path/to/directory/*
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $path_to_file" HEAD
# Prune branch
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# Rewrite history in remote
git push --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment