Skip to content

Instantly share code, notes, and snippets.

@codenathan
Created September 8, 2023 12:12
Show Gist options
  • Save codenathan/c650e2813b6365d8de6035a5c6c1e9a3 to your computer and use it in GitHub Desktop.
Save codenathan/c650e2813b6365d8de6035a5c6c1e9a3 to your computer and use it in GitHub Desktop.
Remove File From Git Commit History

Git provides a native way to remove a file from the entire commit history

Make sure you backup your repository before attempting this.

Use the git filter-branch command to remove the file from all commits in your repository history.

Replace <file_path> with the actual file path and name from the root of your project:

git filter-branch --force --tree-filter 'rm -f <file_path>' --prune-empty -- --all

Run Git's garbage collection to clean up unnecessary objects:

 git reflog expire --expire=now --all && git gc --prune=now --aggressive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment