Skip to main content

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:
--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:
Disabling hash rewriting means commit references in messages will be incorrect after filtering.

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:
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:
Or use --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

Hash Rewriting LimitationsCommit hashes in messages won’t be updated if:
  • The hash doesn’t exist in the repository
  • The commit was pruned during filtering
  • The abbreviated hash isn’t unique
  • You used --preserve-commit-hashes
Suboptimal cases are logged to .git/filter-repo/suboptimal-issues
Binary DataCommit messages are bytes, not strings. Always use:
  • b"text" for literals
  • .split(b"\n") for line splitting
  • b"".join() for joining

Testing Changes

Preview with —dry-run

This saves filtered output to files for inspection without modifying the repository.

Test on Single Branch

Verify Results

Check commit messages after filtering:

Best Practices

Testing Strategy
  1. Test on a small branch first
  2. Use --dry-run for complex operations
  3. Run --analyze before and after to compare
  4. Search for patterns you’re trying to remove
  5. Check edge cases (empty messages, very long messages)
Preserve HistoryBefore running:

Next Steps