mailmap Git Command Guide
Git mailmap allows mapping multiple author names and email addresses to canonical names and email addresses. This ensures consistent attribution across different email aliases, name formats, and email addresses used by the same person in Git commits.
git check-mailmap Syntax:
Section titled “git check-mailmap Syntax:”git check-mailmap [--stdin] [--mailmap-file=<file>] [--] [<contact>...]Mailmap File Format:
Section titled “Mailmap File Format:”Basic email normalization:
Section titled “Basic email normalization:”Proper Name <proper@email.com>Name and email mapping:
Section titled “Name and email mapping:”Proper Name <proper@email.com> <commit@email.com>Nick Name <nick@email.com> <original@email.com>Multiple aliases to one person:
Section titled “Multiple aliases to one person:”Canonical Name <canonical@email.com> <alias1@email.com>Canonical Name <canonical@email.com> <alias2@email.com>Canonical Name <canonical@email.com> Name <alias3@email.com>Email only normalization:
Section titled “Email only normalization:”<canonical@email.com> <alias@email.com>Mailmap Configuration:
Section titled “Mailmap Configuration:”Project mailmap file:
Section titled “Project mailmap file:”# .mailmap file in repository rootProper Name <proper@email.com> improper@email.comNick Name <nick@email.com> <original@email.com>Canonical Name <canonical@email.com> <alias1@email.com>Canonical Name <canonical@email.com> <alias2@email.com>Global mailmap configuration:
Section titled “Global mailmap configuration:”# Set global mailmap filegit config --global mailmap.file ~/.mailmap
# Use multiple mailmap filesgit config --global mailmap.file 'file:///home/user/.mailmap'git config mailmap.file '.mailmap'Automatic mailmap usage:
Section titled “Automatic mailmap usage:”# Show log with mailmap mappinggit log --use-mailmap
# Shortlog with consistent namesgit shortlog --group=author --use-mailmap
# Blame with proper namesgit blame --use-mailmap HEADMailmap File Options:
Section titled “Mailmap File Options:”| Option | Description |
|---|---|
--stdin | Read contacts from standard input |
--mailmap-file=<file> | Use specified mailmap file |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
<contact>... | Name and email addresses to normalize |
Identity Mapping Examples:
Section titled “Identity Mapping Examples:”Single name normalization:
Section titled “Single name normalization:”# Input: Alias Name <alias@email.com># Mailmap: Canonical Name <canonical@email.com> <alias@email.com># Output: Canonical Name <canonical@email.com>Email-only correction:
Section titled “Email-only correction:”# Input: Name <old@email.com># Mailmap: <new@email.com> <old@email.com># Output: Name <new@email.com>Multiple identities one person:
Section titled “Multiple identities one person:”# Input: Various formats from different commits# Mailmap entries:# Canonical Name <canonical@email.com> <work@email.com># Canonical Name <canonical@email.com> <personal@email.com># Canonical Name <canonical@email.com> Old Name <old@email.com># Output: All resolve to Canonical Name <canonical@email.com>Basic Usage Examples:
Section titled “Basic Usage Examples:”Check single contact:
Section titled “Check single contact:”# Check if email is mappedgit check-mailmap "jsmith@example.com"
# Check name and emailgit check-mailmap "John Smith <jsmith@example.com>"Process multiple contacts:
Section titled “Process multiple contacts:”# Check multiple entriesgit check-mailmap "Developer A <a@company.com>" "Dev B <b@company2.com>"
# Read from stdinecho -e "name1@email.com\nname2@email.com" | git check-mailmap --stdinUse custom mailmap file:
Section titled “Use custom mailmap file:”# Use different mailmap filegit check-mailmap --mailmap-file="/path/to/other.mailmap" user@example.com
# Combine with project mailmapgit check-mailmap --mailmap-file=".mailmap" john.doe@example.comAdvanced Mailmap Setup:
Section titled “Advanced Mailmap Setup:”Repository collaboration scenarios:
Section titled “Repository collaboration scenarios:”Corporate environment:
Section titled “Corporate environment:”# .mailmap for enterprise developmentJohn Doe <john.doe@company.com> <john.doe@personal.com>John Doe <john.doe@company.com> JohnnyD <johnny@old-company.com>Jane Smith <jane.smith@company.com> <jane.smith@consulting.com>Jane Smith <jane.smith@company.com> Jane <jane@vendor.com>Open-source project:
Section titled “Open-source project:”# Contributors using different emailsMaintainer <maintainer@example.org> <maintainer@gmail.com>Maintainer <maintainer@example.org> maint <maint@old-email.com>Contributor <contributor@example.org> <contrib@personal.com>Contributor <contributor@example.org> contrib <contrib@work.com>Name standardization:
Section titled “Name standardization:”# Handle different name variations# Input variations: John, Johnny, J. Doe, john doe# All map to: John DoeJohn Doe <john.doe@example.com> John <john@email.com>John Doe <john.doe@example.com> Johnny <johnny@email.com>John Doe <john.doe@example.com> J. Doe <j.doe@email.com>John Doe <john.doe@example.com> john doe <john@email.com>Integration with Git Features:
Section titled “Integration with Git Features:”Log and shortlog consistency:
Section titled “Log and shortlog consistency:”# View commit history with consistent namesgit log --use-mailmap --format="%aN <%aE>"
# Generate contributor statisticsgit shortlog --group=author --use-mailmap -n
# Show contributions by authorgit shortlog --group=author --use-mailmap -snBlame with proper attribution:
Section titled “Blame with proper attribution:”# Show blame with canonical namesgit blame --use-mailmap HEAD -- file.txt
# Track changes by person, not emailgit blame --use-mailmap HEAD | grep "Canonical Name"Reflog with consistent identity:
Section titled “Reflog with consistent identity:”# View reflog with mapped identitiesgit reflog --use-mailmap | head -10
# Find operations by specific persongit reflog --grep="Canonical Name" --use-mailmapMailmap Validation and Debugging:
Section titled “Mailmap Validation and Debugging:”Verify mailmap configuration:
Section titled “Verify mailmap configuration:”# Check mailmap file locationgit config --list | grep mailmap
# Test mailmap mappingsgit check-mailmap --mailmap-file=".mailmap" "testuser@example.com"
# Validate against commit historygit log --use-mailmap --all --format="%aN <%aE>" | sort | uniq -c | sort -nrFind unmapped contributors:
Section titled “Find unmapped contributors:”# Identify contributors without mailmap entriesgit log --pretty="%aN <%aE>" | sort | uniq > all-contributors.txt
# Check which ones are unmappedwhile read -r contributor; do result=$(git check-mailmap "$contributor") if [ "$result" != "$contributor" ]; then echo "Mapped: $contributor -> $result" else echo "Unmapped: $contributor" fidone < all-contributors.txtStatistics and analysis:
Section titled “Statistics and analysis:”# Count total contributors (before/after mailmap)echo "Before mailmap:"git log --pretty="%aN <%aE>" | sort | uniq | wc -l
echo "After mailmap:"git log --pretty="%aN <%aE>" --use-mailmap | sort | uniq | wc -l
# Find duplicate names that should be the same persongit log --pretty="%aN" --use-mailmap | sort | uniq -dConfiguration Best Practices:
Section titled “Configuration Best Practices:”File naming and location:
Section titled “File naming and location:”# Repository-specific mailmap.mailmap
# Global mailmap for all repositories~/.git-mailmap
# Organization-wide mailmap/path/to/company/.mailmapSystematic name standardization:
Section titled “Systematic name standardization:”# .mailmap example for consistent formatting
# Standardize to "First Last <email>"" formatJohn Smith <john.smith@example.com> <jsmith@example.com>John Smith <john.smith@example.com> Smith, John <johnsmith@example.com>John Smith <john.smith@example.com> jsmith <jsmith@example.com>
# Handle name variationsSarah Johnson <sarah.johnson@example.com> Sarah <sjohnson@example.com>Sarah Johnson <sarah.johnson@example.com> S. Johnson <sjohnson@example.com>Email domain normalization:
Section titled “Email domain normalization:”# Map different email providers/servers for same personDeveloper <developer@company.com> <dev@gmail.com>Developer <developer@company.com> Developer <dev@company-mail.com>Developer <developer@company.com> dev <dev@old-domain.com>Troubleshooting Common Issues:
Section titled “Troubleshooting Common Issues:”Mailmap not working:
Section titled “Mailmap not working:”# Check if mailmap file existsls -la .mailmapcat .mailmap
# Verify mailmap syntaxgit check-mailmap --mailmap-file=".mailmap" "test@example.com"
# Check git configurationgit config --list | grep mailmapIncorrect mappings:
Section titled “Incorrect mappings:”# Test specific mappinggit check-mailmap "Problem Case <problem@example.com>"
# Debug mapping logic# Edit .mailmap and test incrementallyecho "Test Case <test@example.com>" >> .mailmapgit check-mailmap "Test Case <test@example.com>"Case sensitivity issues:
Section titled “Case sensitivity issues:”# Email addresses are case-sensitive# Names are case-sensitive in mailmap# Check for exact matchesgit check-mailmap "John Doe <john@example.com>"Permissions and access:
Section titled “Permissions and access:”# Mailmap file should be trackedgit ls-files | grep -i mailmap
# Make sure it's readablels -la .mailmapReal-World Usage Examples:
Section titled “Real-World Usage Examples:”Corporate contributor normalization:
Section titled “Corporate contributor normalization:”# Handle corporate identity changesFormer Name <current@company.com> Former <former@company.com>Former Name <current@company.com> fname <fname@oldcompany.com>
# Map contractor identitiesEmployee <employee@company.com> Contractor <contractor@vendor.com>Employee <employee@company.com> consultant <consultant@agency.com>Open-source contribution mapping:
Section titled “Open-source contribution mapping:”# Handle different contribution platformsContributor <contributor@example.org> contributor@github.com <github-id@users.noreply.github.com>Contributor <contributor@example.org> contrib <contrib@sourceforge.net>Contributor <contributor@example.org> Contributor <contrib@patchwork.kernel.org>Automated mailmap maintenance:
Section titled “Automated mailmap maintenance:”#!/bin/bash# Generate mailmap from git log analysis
echo "# Auto-generated mailmap based on contributor patterns" > .mailmapecho "" >> .mailmap
# Find contributors and generate mappingsgit log --pretty="%aN|%aE" | sort | uniq | \while IFS='|' read -r name email; do if [[ $email == *"noreply"* ]] || [[ $email == *"users"* ]]; then # Likely GitHub/GitLab generated base_email=$(echo "$email" | sed 's/+.*@/@/;s/@users.noreply.//;s/@.*noreply.//') echo "$name <$base_email> <$email>" >> .mailmap fidone
echo "Generated mailmap:"cat .mailmapHow does mailmap relate to .authors or credits files?
Section titled “How does mailmap relate to .authors or credits files?”Mailmap provides programmatic mapping for Git commands, while .authors files are human-readable. Mailmap affects git log/blame output automatically.
What’s the difference between mailmap and Git author configuration?
Section titled “What’s the difference between mailmap and Git author configuration?”Mailmap maps existing commits’ author information; git config sets author for new commits. Mailmap is retrospective, config is prospective.
Can mailmap handle committed author information changes?
Section titled “Can mailmap handle committed author information changes?”Yes, it can map old author names/emails to canonical ones. Use rename detection to find all variations used by a contributor.
How do I create mailmap entries from existing commits?
Section titled “How do I create mailmap entries from existing commits?”Analyze git log output to identify author variations: git log —pretty=“%aN <%aE>” | sort | uniq. Then create mappings for each variation.
What’s the performance impact of mailmap?
Section titled “What’s the performance impact of mailmap?”Negligible - mailmap lookup is fast unless using very large files. Load time is minimal compared to git log operations.
Can mailmap work with GitHub/GitLab profiles?
Section titled “Can mailmap work with GitHub/GitLab profiles?”No direct integration, but can map GitHub-generated email addresses to canonical identities. Useful for contributor consistency across platforms.
How do I share mailmap across multiple repositories?
Section titled “How do I share mailmap across multiple repositories?”Keep mailmap file in each repository, or use global mailmap configuration. Shared organization repositories can benefit from team mailmap standards.
What’s the syntax for name-only mapping?
Section titled “What’s the syntax for name-only mapping?”Name-only mapping: “Canonical Name canonical@email.com” without additional parameters maps the canonical name to itself for consistency.
Can mailmap handle international characters?
Section titled “Can mailmap handle international characters?”Yes, fully supports UTF-8 encoding. Mailmap files should be UTF-8 encoded for proper international name handling.
How do I validate mailmap correctness?
Section titled “How do I validate mailmap correctness?”Use git check-mailmap to test mappings, and git log —use-mailmap to verify display changes. Review output for unexpected consolidations.
What’s the relationship between mailmap and Git aliases?
Section titled “What’s the relationship between mailmap and Git aliases?”Mailmap maps contributor identities; Git aliases are shortcuts for commands. Different purposes - mailmap for contributor attribution consistency.
Can mailmap be used for commit message formatting?
Section titled “Can mailmap be used for commit message formatting?”No - mailmap only affects author/committer names and emails, not commit messages, subjects, or other commit metadata.
Applications of the mailmap command
Section titled “Applications of the mailmap command”- Contributor Attribution: Ensure consistent author attribution across different email aliases and name variations
- Project Analytics: Generate accurate statistics on contributions by consolidating multiple identities of same person
- Code Review Integrity: Provide consistent author identification in code review tools and workflows
- Compliance Reporting: Enable accurate contributor tracking for license compliance and security audits
- Open-Source Project Management: Maintain proper credit attribution for contributions from various platforms and aliases
- Corporate Collaboration: Standardize contributor identities across different company domains and naming conventions