Overview
Commit message rewriting allows you to fix typos, update references, add metadata, or standardize formatting across your entire repository history.Replace Text in Messages
Basic Replacement
Replace text in commit and tag messages:- Create expressions.txt
- Run filter-repo
--replace-message uses the same syntax as --replace-text, but only applies to commit and tag messages, not file contents.Replacement Syntax
Supports literal text, globs, and regex:Using Message Callback
Add Metadata
Add Signed-off-by or other metadata:Fix Formatting
Standardize commit message format:Update Issue References
Convert between issue tracking systems:Rewriting Commit Hashes
Automatic Hash Updates
By default, git-filter-repo updates commit hash references in messages:Automatic hash rewriting:
- Preserves abbreviated hash length
- Only updates hashes of commits being rewritten
- Skips hashes that don’t exist or were pruned
Disable Hash Rewriting
Prevent automatic hash updates:Encoding Handling
Default Behavior
By default, git-filter-repo re-encodes commit messages to UTF-8:Preserve Original Encoding
Keep commit message encodings unchanged:If a commit message isn’t valid in its specified encoding, git won’t re-encode it (it will leave both the message and encoding header unchanged).
Complex Examples
Standardize Commit Format
Enforce Conventional Commits format:Add Issue Links
Automatically link to issue tracker:Remove Sensitive Information
Redact sensitive data from commit messages:Prefix All Commits
Add a prefix to all commit messages:Clean Up Merge Messages
Standardize merge commit messages:Tag Messages
Modify Tag Messages
Tag messages are modified with--replace-message too:
--tag-callback for more control:
Add Tag Metadata
Multi-Line Messages
Format Multi-Line Messages
Handle messages with multiple paragraphs:Common Patterns
Fix Common Typos
typos.txt
Update Project URLs
urls.txt
Remove Debug Messages
Add Co-authored-by
Add co-authors based on commit content:Limitations
Binary DataCommit messages are bytes, not strings. Always use:
b"text"for literals.split(b"\n")for line splittingb"".join()for joining
Testing Changes
Preview with —dry-run
Test on Single Branch
Verify Results
Check commit messages after filtering:Best Practices
Next Steps
- Learn about Advanced Filtering for complex callbacks
- Explore Library Usage for programmatic control
- See Basic Filtering for path operations
