LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-obliterate

Remove file from entire history

TLDR

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

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
copy
sudo dnf install git
copy
sudo pacman -S git
copy
sudo apk add git
copy
sudo zypper install git
copy
brew install git
copy
nix profile install nixpkgs#git
copy

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

RESOURCES

Copied to clipboard
Kai