Created
February 10, 2021 20:15
-
-
Save edthrn/f8bd64c849e654cedd7a70412777c515 to your computer and use it in GitHub Desktop.
Remove old data from Git repo and 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
# Taken from https://docs.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository | |
# Warning: | |
# -------- | |
# All stashes may be lost! | |
PATH_TO_REMOVE=big-folder/commited/by/error | |
# 1. Force Git to process, but not check out, the entire history of every branch and tag | |
# 2. Remove the specified file, as well as any empty commits generated as a result | |
# 3. Overwrite existing tag | |
git filter-branch --force --index-filter \ | |
"git rm -rf --cached --ignore-unmatch $PATH_TO_REMOVE" \ | |
--prune-empty --tag-name-filter cat -- --all | |
git push origin -f --all | |
git push origin -f --tags # if necessary | |
# All collaborators must now REBASE their local branches on this one. | |
# MERGE is forbidden: it may re-introduce the files we just got rid of. | |
# It nothing caused unintended side-effects: | |
git for-each-ref --format="delete %(refname)" refs/original | git update-ref --stdin | |
git reflog expire --expire=now --all | |
git gc --prune=now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative (but very similar) method described here https://stackoverflow.com/a/27745221