Purge a file from history
Completely purges a file from history.
- Use
git rm --cached --ignore-unmatch <path>
to delete the file in the specified<path>
. - Use
git filter-branch --force --index-filter <command> --prune-empty --tag-name-filter cat -- --all
to rewrite the branch's history, passing it the previous command. - You can optionally use
git push <remote> --force -all
to force push the changes to the remote repository. - ⚠️ WARNING: This is a destructive action that rewrites the history of the entire repository. Make sure you know what you are doing.
git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch <path>" \ --prune-empty --tag-name-filter cat -- --allgit push <remote> --force --allExamplesgit filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch config/apiKeys.json" \ --prune-empty --tag-name-filter cat -- --all# Purges `config/apiKeys.json` from historygit push origin --force --all# Force pushes the changes to the remote repository
Sign for comment
You can write your questions about the subject below.
LoginYour information is only used to display your name and reply by email.
- M.samet.29 Jun 2021 at 6:32 AMhi this message from git purge a file from history
- M.samet.29 Jun 2021 at 6:33 AMand this second message for debug git