How to permanently delete a file stored in GIT (both from the local and remote repositories)?

发布时间 2023-12-22 10:51:41作者: yohohoo

First run

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all

Then shrink the .git folder

rm -rf .git/refs/original/

git reflog expire --expire=now --all

git gc --prune=now

git gc --aggressive --prune=now

Now push all the changes to the remote repository

git push --all --force

 

**Acknowledgement to https://stackoverflow.com/a/24526351