Path Filtering Options
Path filtering options control which files and directories are included in the filtered repository history.Renames are NOT automatically followed. If a file or directory was renamed in history, you need to specify both the old and new paths.
Basic Path Selection
—path, —path-match
Exact path (file or directory) to include in filtered history.Type: File or directory pathMultiple: Yes - can be specified multiple times for union of pathsExample:This includes only the
src/ directory and README.md file.—path-glob
Glob pattern of paths to include in filtered history.Type: Glob patternMultiple: Yes - can be specified multiple times for union of pathsExample:This includes all Python files and all Markdown files in the docs directory.
Use quotes to prevent shell glob expansion
—path-regex
Regular expression of paths to include in filtered history.Type: Python regex patternMultiple: Yes - can be specified multiple times for union of pathsExample:This includes Python and JavaScript files in the src directory.
Uses Python regex syntax: https://docs.python.org/3/library/re.html
Path Selection Modifiers
—invert-paths
Invert the selection of files from path options.When enabled, only files matching NONE of the path options are selected.Example:This removes all .log files from history.
—use-base-name
Match on file basename instead of full path.Incompatible with: This includes all README.md files regardless of their directory.
--path-renameCannot match: Directory namesExample:Path Shortcuts
—paths-from-file
Specify multiple path filtering and renaming directives from a file.Format: One directive per linePrefixes:Usage:
literal:(default) - Exact matchglob:- Glob patternregex:- Regular expression
==> separatorComments: Lines starting with # are ignoredExample file (paths.txt):—subdirectory-filter
Extract a subdirectory and make it the project root.Only history touching the subdirectory is kept, and that directory becomes the new root.Equivalent to:Example:Contents of
mysubdir/ become the new repository root.—to-subdirectory-filter
Move the project root into a subdirectory.All files are moved into the specified subdirectory.Equivalent to:Example:All repository contents are moved under
myproject/.Usage Examples
Keep Only Specific Directories
src/ and docs/ directories plus the README file.
Remove Specific Files
Keep Files by Pattern
Combined Filtering
src/main/, then removes any files named data under any subdirectory.
Multiple filter-repo runs can be chained for complex filtering scenarios.
Important Notes
Trailing Slashes
Directory names can be specified with or without trailing slashes:Processing Order
All path arguments are processed in the order specified. This matters for renames:See Also
- Rename Options → - Path renaming
- Content Options → - Content filtering
- Examples → - Real-world examples
