Overview
Content-based filtering allows you to modify file contents, remove large files, or replace sensitive data across your entire repository history. This is essential for cleaning up committed secrets, fixing typos, or removing unwanted content.Text Replacement
Replace Sensitive Data
Remove passwords, tokens, or other sensitive text from history:- Create expressions.txt
- Run filter-repo
Replacement Syntax
The expressions file supports multiple formats:Default ReplacementIf
==> is not specified, the default replacement is ***REMOVED***.Regex Features
Python regex syntax is supported:Stripping Large Files
By Size Threshold
Remove all files larger than a specific size:By Blob ID
Remove specific files by their git object hash:- Find Blob IDs
- Remove Blobs
Modifying File Contents
Using Blob Callback
Modify file contents programmatically:Binary DetectionCheck for null bytes in first 8KB to detect binary files:
Using File Info Callback
Filter based on filename, mode, and contents:Apply Replace Text Selectively
Use--replace-text with --file-info-callback for selective replacement:
Performance Optimization
Cache Transformations
Avoid reprocessing the same blob multiple times:Sensitive Data Removal
For removing sensitive data (passwords, API keys, etc.):Step 1: Prepare
Step 2: Create Expressions File
sensitive.txt
Step 3: Remove Data
—sensitive-data-removal flag:
- Fetches all refs (not just branches/tags)
- Tracks first changed commits
- Reports orphaned LFS objects
- Provides cleanup instructions
Step 4: Verify Removal
Step 5: Push and Clean Up
Binary Files
Skip Binary Files
Remove Specific Binary Types
Common Examples
Remove Accidentally Committed .env File
Fix Typo Throughout History
fixes.txt
Sanitize Configuration Files
Remove Debug Logging
File Mode Changes
Modify file permissions in history:Valid Git Modes:
100644- Regular non-executable file100755- Executable file/script120000- Symbolic link160000- Git submodule
Limitations
Multiple MatchesIf a pattern matches multiple times in a file, ALL occurrences are replaced.
Next Steps
- Learn about Commit Message Rewriting
- Explore Advanced Filtering for complex operations
- See Library Usage for programmatic filtering
