“git filter-repo” is a powerful and versatile tool used for rewriting Git history. It provides advanced capabilities for modifying the commit history, filtering out unwanted data, and transforming the structure of a Git repository.
Here’s an overview of its features and functionality:
- History Filtering: With “git filter-repo,” you can selectively filter the commit history based on various criteria. This includes filtering commits by author, date range, file paths, commit messages, and more. It allows you to include or exclude specific commits, branches, or tags, providing fine-grained control over the resulting history.
- Content Filtering: The tool enables you to filter the content of commits, such as removing files, modifying file contents, or even splitting and merging commits. This can be useful for removing sensitive data, large files, or irrelevant content from the repository’s history.
- Branch and Tag Manipulation: “git filter-repo” allows you to rename branches or tags, delete specific branches, or combine multiple branches into one. It provides flexibility in restructuring the repository’s branch and tag structure.
- Commit Message Editing: You can modify commit messages using “git filter-repo.” It supports changing the content, prefix, suffix, or even completely rewriting commit messages.
- Custom Transformations: The tool supports custom transformations using Python scripts. This enables you to apply complex logic to modify the history, perform data conversions, or implement custom filtering rules.
- Performance and Scalability: “git filter-repo” is designed to handle large repositories with millions of commits efficiently. It employs various optimization techniques to ensure fast processing and minimal resource usage.
Using “git filter-repo,” you can reshape the history of a Git repository according to your specific requirements. This can be useful for cleaning up a repository, extracting a subset of commits, creating project-specific forks, or preparing a repository for migration or publication.
It’s important to note that “git filter-repo” is a separate tool that needs to be installed and invoked independently from the standard Git commands. It provides extensive documentation and examples to guide users through its usage and customization options.
git filter-repo Command Examples
1. Replace a sensitive string in all files:
# git filter-repo --replace-text replacement')
2. Extract a single folder, keeping history:
# git-filter-repo --path /path/to/folder
3. Remove a single folder, keeping history:
# git-filter-repo --path path/to/folder --invert-paths
4. Move everything from sub-folder one level up:
# git-filter-repo --path-rename path/to/folder/: