Sunday, June 18, 2023

Delete a file from git history

I have tried multiple commands to delete a file entirely from the git and its history. This is what worked without any issues. This requires force push the changes.
$ git filter-branch --force --index-filter "git rm --cached --ignore-unmatch path-to-file-to-remove.txt" --prune-empty --tag-name-filter cat -- --all
If there is space in the path escape with a slash \.
After that force push to the repo.
$ git push -u origin main --force