From Removing and purging files from git history
To remove files which have been recently added to .gitignore
.
git ls-files --ignored --exclude-standard | xargs git rm --cached
To get a list of entire directories that have been removed from the repository.
git log --all --pretty=format: --name-only --diff-filter=D | sed 's|[^/]+$||g' | sort -u
Filter the git branch untill all the files of the list have been removed.
git log --all --pretty=format: --name-only --diff-filter=D | sed 's|[^/]+$||g' | sort -u | xargs -I {} git filter-branch --tag-name-filter cat --index-filter 'git rm -r --cached --ignore-unmatch "{}"' --prune-empty -f -- --all
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now
Run the same command that was used in the first step above to verify that the files are no longer in history.