Commit Modification Options
Options for modifying commit messages, author/committer names and emails, and controlling how commit ancestry is rewritten.Commit Message Options
—replace-message
Replace text patterns in commit and tag messages.Type: Path to expressions fileFormat: Same syntax as Usage:
--replace-textApplies to: Commit messages and annotated tag messagesExample expressions file (message-replacements.txt):—preserve-commit-hashes
Don’t update commit hash references in commit messages.Default behavior: Commit hash references are automatically updated to new hashesWith this flag: Old commit hash references remain unchangedBy default, git-filter-repo automatically finds commit hash references in messages and updates them to the new post-rewrite hashes, preserving the original abbreviation length.Example:
Use this if you want to preserve original commit references, or if automatic hash updating causes issues.
—preserve-commit-encoding
Don’t re-encode commit messages to UTF-8.Default behavior: Messages are re-encoded to UTF-8 if commit object specifies different encodingWith this flag: Original encoding is preservedRequires: Git >= 2.23.0Example:
Names and Emails
—mailmap
Apply mailmap file to rewrite author, committer, and tagger names/emails.Type: Path to mailmap fileFormat: See Usage:
git-shortlog(1) for mailmap formatApplies to: Authors, committers, and taggersExample mailmap file (.mailmap):If the mailmap file is tracked in git history, only its current contents are used (historical versions are ignored).
—use-mailmap
Use the
.mailmap file from the repository.Equivalent to: --mailmap .mailmapExample:Parent Rewriting
Options that control how commit ancestry is modified during filtering.—replace-refs
Control how replace refs are handled.Type: Choice of strategyOptions:
delete-no-add- Delete existing replace refs, don’t add new onesdelete-and-add- Delete existing, add new for all rewritesupdate-no-add- Update existing, don’t add new (DEFAULT)update-or-add- Update existing, add only if referenced by existing replace refupdate-and-add- Update existing, add new for all rewritesold-default- Use pre-2.45 default behavior
Replace refs must be manually pushed and fetched. See
git-replace(1) for details.—prune-empty
Whether to prune commits that become empty.Type: Choice of strategyOptions:
always- Prune all empty commits (even originally empty ones)auto- Only prune commits that become empty due to filtering (DEFAULT)never- Keep all commits, even if empty
auto):- Prunes commits that become empty due to filtering
- Keeps commits that were originally empty
- When parent is pruned, first non-pruned ancestor becomes new parent
—prune-degenerate
Whether to prune merge commits that become degenerate.Type: Choice of strategyOptions:
always- Prune all degenerate merges (even originally degenerate)auto- Only prune merges that become degenerate due to filtering (DEFAULT)never- Keep all merge commits
- Has fewer than two parents, OR
- Has the same commit as both parents, OR
- Has one parent that is an ancestor of the other
auto):- Merge commits normally exempt from pruning (for topology)
- Prunes merges that become degenerate AND have no file changes
- Only prunes merges that become degenerate, not those that started degenerate
—no-ff
Preserve first parent even if it becomes an ancestor of another parent.Effect: Modifies
--prune-degenerate behaviorUse case: Projects that always use git merge --no-ffNormally, if first parent becomes an ancestor of another parent in a merge, that first parent might be pruned (depending on --prune-degenerate). This flag prevents that.Example:Usage Examples
Update Commit Messages
Create replacements file (messages.txt):Consolidate Author Names
Create mailmap file (.mailmap):Aggressive Pruning
Preserve History Topology
Create Replace Refs for Old Hashes
Mailmap Format
The mailmap file format (fromgit-shortlog):
Important Notes
Empty Commit HandlingThe default
--prune-empty auto is usually what you want:- Keeps originally empty commits (intentional, like “WIP” commits)
- Removes commits that become empty due to filtering
See Also
- Content Options → - Replace text in file contents
- Ref Options → - Rename branches and tags
- Callbacks → - Custom commit processing
- Examples → - Real-world examples
