Deleting files, completely, from git history
git, programming, typescript, git history, clean git history, delete files
Last updated
Was this helpful?
git, programming, typescript, git history, clean git history, delete files
Last updated
Was this helpful?
Specify the name of the file you want to clean with FILENAME=""
.
With the git filter-branch
command, we can clean all traces of a specific file in Git history.
The force
parameter is used to prevent errors when the filter branch already exists.
The index-filter
parameter specifies the command run for each commit.
We remove all versions of the specified file with the git rm --cached --ignore-unmatch $FILENAME
command.
The prune-empty
parameter removes empty commits that do not include file changes.
The tag-name-filter cat -- --all
parameter performs operations on all branches and tags.
We forcefully push the changes to the remote repository with the git push origin --force --all
and git push origin --force --tags
commands.
We delete the original references with the git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
command.
We clean the git history with the git reflog expire --expire=now --all
and git gc --prune=now
commands.