git-obliterate

Remove file from entire history

TLDR

Remove file from entire history
$ git obliterate [filename]
Remove multiple files
$ git obliterate [file1] [file2]
Limit the rewrite to a revision range
$ git obliterate [filename] -- [since]..[until]

SYNOPSIS

git obliterate filename... [-- rev-list-args]

DESCRIPTION

git obliterate completely removes one or more files from Git history. This git-extras command runs `git filter-branch --index-filter 'git rm -r --cached <files> --ignore-unmatch' --prune-empty --tag-name-filter cat` over `--all` refs (or over a revision range given after `--`), erasing the files from every rewritten commit while keeping tags pointed at their (now rewritten) commits.It is useful for removing accidentally committed secrets, credentials, or large files that should never have been tracked. It does not repack the repository afterward; old objects remain until you run garbage collection.

INSTALL

sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apk add git
sudo zypper install git
brew install git
nix profile install nixpkgs#git

CAVEATS

This rewrites history and changes all commit hashes. Coordinate with collaborators before using on shared branches. Run `git reflog expire --expire=now --all && git gc --prune=now --aggressive` afterward to actually reclaim disk space and drop the old blobs.

SEE ALSO

git-filter-branch(1), git-gc(1), git-extras(1)

RESOURCES

Source code · Documentation