Last active
February 9, 2020 00:42
-
-
Save wcarhart/719c56ad47c9ccb327666ab9150f6632 to your computer and use it in GitHub Desktop.
Completely remove a file from Git history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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