Skip to content

mailinfo Git Command Guide

The git mailinfo command reads a single email message from standard input and extracts the commit log message and patches, writing the commit message to a file and patches to another file. It extracts author name, email, and subject for use by git am to create commits.

Terminal window
git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n]
[--[no-]scissors] [--quoted-cr=<action>]
<msg> <patch>
OptionDescription
-kKeep email cruft in Subject header
-bRemove email cruft from Subject header
-uConvert email encoding to UTF-8
--encoding=<encoding>Specify email encoding
-nDon’t convert email encoding
--scissorsEnable scissors detection
--no-scissorsDisable scissors detection
--quoted-cr=<action>Handle quoted CR (warn/crlf/convert)
ParameterDescription
<msg>File to write commit log message to
<patch>File to write patches to
From: Author Name <author@example.com>
Date: Thu, 01 Jan 2023 12:00:00 +0000
Subject: [PATCH] Add new feature
Commit message here
---
Patch content here
# Scissors line separates message from patch
-- >8 --
<commit message>
<patch content>
# Handle different line ending styles
--quoted-cr=warn # Warn about quoted CR
--quoted-cr=crlf # Convert to CRLF
--quoted-cr=convert # Convert quoted CR to LF
Terminal window
# Read email from stdin, extract message and patch
cat email.eml | git mailinfo msg.txt patch.txt
# Process email with specific encoding
cat email.eml | git mailinfo --encoding=iso-8859-1 msg.txt patch.txt
# Preserve email formatting in subject
cat email.eml | git mailinfo -k msg.txt patch.txt
Terminal window
# Complete email to patch workflow
cat email.eml | git mailinfo msg.txt patch.txt
echo "$(cat msg.txt)" | git am --patch-format=mbox patch.txt
# Process multiple emails
for email in *.eml; do
base=$(basename "$email" .eml)
cat "$email" | git mailinfo "${base}-msg.txt" "${base}-patch.txt"
done
Terminal window
# Handle emails with scissors
cat email-with-scissors.eml | git mailinfo --scissors msg.txt patch.txt
# Process with UTF-8 conversion
cat international-email.eml | git mailinfo -u msg.txt patch.txt
# Custom quoted CR handling
cat windows-email.eml | git mailinfo --quoted-cr=convert msg.txt patch.txt
#!/bin/bash
# Process incoming email patches
# Extract message and patch
cat email.eml | git mailinfo commit-msg.txt patch-file.txt
# Apply patch if extraction successful
if [ -s "patch-file.txt" ]; then
git am --patch-format=mbox patch-file.txt
# Clean up temporary files
rm commit-msg.txt patch-file.txt
else
echo "No patch found in email"
exit 1
fi
Terminal window
# Process emails from mail client
# Save email as .eml file, then process
cat saved-email.eml | git mailinfo -u commit-msg.txt patch.txt
# Apply with proper authorship
AUTHOR_INFO=$(cat commit-msg.txt | head -1)
echo "Patch from: $AUTHOR_INFO"
git am patch.txt
Terminal window
# Process multiple email patches
for eml_file in patch-emails/*.eml; do
base=$(basename "$eml_file" .eml)
# Extract patch information
cat "$eml_file" | git mailinfo "${base}-msg.txt" "${base}-patch.txt"
# Apply if patch exists
if [ -s "${base}-patch.txt" ]; then
git am "${base}-patch.txt"
echo "Applied patch: $base"
fi
done
Terminal window
# Default behavior (remove cruft)
# Input: [PATCH v2] Add feature
# Output: Add feature
# Keep cruft with -k
# Input: [PATCH v2] Add feature
# Output: [PATCH v2] Add feature
# Custom processing
cat email.eml | git mailinfo -b msg.txt patch.txt # Remove cruft
Terminal window
# Extract commit message
cat email.eml | git mailinfo msg.txt patch.txt
cat msg.txt # Shows extracted commit message
# Handle multi-part messages
cat multipart-email.eml | git mailinfo --scissors msg.txt patch.txt
Terminal window
# Extract patch to file
cat patch-email.eml | git mailinfo msg.txt patch.txt
ls -la patch.txt # Shows extracted patch
# Process inline patches
cat inline-patch.eml | git mailinfo msg.txt patch.txt
Terminal window
# Configure default encoding
git config mailinfo.encoding UTF-8
# Handle specific email clients
git config mailinfo.scissors true
# Configure CR handling
git config mailinfo.quotedcr convert
# Custom email processing script
#!/bin/bash
# Enhanced mailinfo processing
# Extract with custom options
cat "$1" | git mailinfo \
--encoding=UTF-8 \
--scissors \
--quoted-cr=convert \
"${1%.eml}-msg.txt" \
"${1%.eml}-patch.txt"
# Validate extraction
if [ -s "${1%.eml}-patch.txt" ]; then
echo "Patch extracted successfully"
else
echo "No patch found in email"
fi
Terminal window
# Check email format
cat email.eml | head -20
# Test with known good email
cat good-email.eml | git mailinfo test-msg.txt test-patch.txt
# Debug encoding issues
cat email.eml | git mailinfo --encoding=UTF-8 msg.txt patch.txt
Terminal window
# Check if patch was extracted
ls -la patch.txt
cat patch.txt | head -5
# Verify message extraction
cat msg.txt
# Manual patch extraction if needed
grep -A 1000 "^---$" email.eml > manual-patch.txt
Terminal window
# Check for scissors line
cat email.eml | grep -n ">8\|--8<\|-- >8"
# Force scissors processing
cat email.eml | git mailinfo --scissors msg.txt patch.txt
# Disable scissors if causing issues
cat email.eml | git mailinfo --no-scissors msg.txt patch.txt
Terminal window
# Detect email encoding
cat email.eml | grep -i "content-type" | head -1
# Try different encodings
cat email.eml | git mailinfo --encoding=iso-8859-1 msg.txt patch.txt
# Convert encoding manually
iconv -f iso-8859-1 -t utf-8 email.eml | git mailinfo -u msg.txt patch.txt
#!/bin/bash
# Process patches from mailing list
# Download email from list
curl -s "https://lists.example.com/msg.eml" > patch.eml
# Extract patch information
cat patch.eml | git mailinfo commit-msg.txt patch.txt
# Apply patch with proper authorship
if [ -s "patch.txt" ]; then
# Get author information from email
author=$(cat commit-msg.txt | head -1)
echo "Applying patch from: $author"
# Apply patch
git am --patch-format=mbox patch.txt
# Clean up
rm commit-msg.txt patch.txt patch.eml
else
echo "No patch found in email"
fi
Terminal window
# Process internal code review emails
# Extract review information
cat review-email.eml | git mailinfo \
--encoding=UTF-8 \
--scissors \
review-msg.txt review-patch.txt
# Apply with review tracking
if [ -s "review-patch.txt" ]; then
git am review-patch.txt
# Add review notes
git notes add -m "Reviewed: $(date)" HEAD
git notes append -m "Reviewer: $(git config user.name)"
fi
#!/bin/bash
# Validate incoming patches
validate_patch() {
local email_file="$1"
# Extract patch
cat "$email_file" | git mailinfo msg.txt patch.txt
# Check if patch extracted
if [ ! -s "patch.txt" ]; then
echo "ERROR: No patch found in $email_file"
return 1
fi
# Validate patch format
if ! git apply --check patch.txt 2>/dev/null; then
echo "ERROR: Invalid patch format in $email_file"
return 1
fi
# Check commit message quality
if [ "$(cat msg.txt | wc -l)" -lt 3 ]; then
echo "WARNING: Short commit message in $email_file"
fi
echo "✓ Valid patch: $email_file"
return 0
}
# Process all emails in directory
for eml in incoming-patches/*.eml; do
validate_patch "$eml"
done

How does mailinfo work with different email formats?

Section titled “How does mailinfo work with different email formats?”

Processes standard email headers (From, Date, Subject) and extracts commit message and patch content. Handles various email formats including multipart and different encodings.

What’s the difference between -k and -b options?

Section titled “What’s the difference between -k and -b options?”

-k preserves email cruft in subject line (like [PATCH v2]), -b removes it for cleaner commit messages. Use -k when processing git format-patch -k output.

Processes text content only. HTML emails should be converted to plain text first or use email clients that can extract plain text patches.

mailinfo processes inline patches. For attachments, extract patch files manually first, then process with mailinfo for message extraction.

Detects ”— >8 —” line that separates commit message from patch content in emails. Helps with proper message/patch separation.

Can mailinfo process multiple patches in one email?

Section titled “Can mailinfo process multiple patches in one email?”

Processes first patch found. For multiple patches, split email or use git am which handles series automatically.

How do I handle international characters in emails?

Section titled “How do I handle international characters in emails?”

Use -u or —encoding options to handle non-ASCII characters. Configure proper encoding for international development teams.

What’s the relationship between mailinfo and git am?

Section titled “What’s the relationship between mailinfo and git am?”

mailinfo is low-level tool used by git am. git am calls mailinfo internally to extract patches and messages from emails.

Can mailinfo work with Outlook/Exchange emails?

Section titled “Can mailinfo work with Outlook/Exchange emails?”

Yes, processes standard email formats. May need encoding adjustments for different email clients. Test with sample emails first.

How do I handle quoted-printable encoding?

Section titled “How do I handle quoted-printable encoding?”

mailinfo handles quoted-printable automatically. Use —encoding option if manual encoding specification needed.

Writes commit message to file, patches to file, and author/subject information to stdout for git am consumption.

Can mailinfo process nested email threads?

Section titled “Can mailinfo process nested email threads?”

Processes the primary email content. Thread information may be preserved in commit message depending on email structure.

mailinfo doesn’t limit patch size. Large patches processed normally. Use git apply —check to validate large patches before applying.

Processes email content regardless of signatures. Email signatures may appear in commit message unless using scissors separation.

Handles different line ending styles in emails. Convert quoted CR characters to appropriate line endings for the platform.

How do I integrate mailinfo with custom email processing?

Section titled “How do I integrate mailinfo with custom email processing?”

Use in shell scripts for automated patch processing. Combine with email filtering and validation for robust patch workflows.

Processes text-based patches. Binary patches should be handled separately or use appropriate encoding options.

Check email format, try different encoding options, verify scissors settings, test with known good emails, check file permissions.

What’s the performance impact of mailinfo?

Section titled “What’s the performance impact of mailinfo?”

Very fast - processes email text parsing. Performance mainly depends on email size and encoding complexity.

Yes, processes individual emails from mbox files. Extract individual emails first or use git am for mbox processing.

How do I handle emails with multiple patches?

Section titled “How do I handle emails with multiple patches?”

mailinfo processes first patch found. For multiple patches, use git am which handles patch series automatically.

  1. Patch Management: Extract patches from email for application to Git repositories
  2. Code Review Integration: Process emailed patches for automated review workflows
  3. Mailing List Integration: Handle patches submitted through project mailing lists
  4. Collaborative Development: Enable email-based patch submission and review processes
  5. Automated Processing: Build systems for processing incoming email patches
  6. Archive Management: Extract and organize patches from email archives for historical analysis