git-mailinfo
Extract patch information from email messages
TLDR
Extract the patch and author data from an email message
Extract but remove leading and trailing whitespace
Remove everything from the body before a scissors line (e.g. "-->* --") and retrieve the message or patch
SYNOPSIS
git mailinfo [options...] <msgfile> <patchfile>
PARAMETERS
-k, --keep-subject
Do not strip [PATCH] nor [GIT:PATCH] from subject line.
-b, --keep-non-patch
Treat non-patch message as patchfile content (for compatibility; rarely needed).
-t from, --thread=from
Threading message ID to use for In-Reply-To header.
-s file, --reply-to=file
File to write possible Reply-To header value.
-u, --utf8
Assume message body uses UTF-8 encoding.
--encoding=encoding
Specify encoding of the message body (overrides autodetect).
--scissors
Use scissors heuristics to cut excessive context lines.
--strip-trailing-cr
Strip carriage-return from line endings (default).
--no-strip-trailing-cr
Do not strip carriage-return characters.
DESCRIPTION
git-mailinfo is a Git plumbing command that parses a single e-mail message in mbox format, extracting the patch content and associated metadata such as author name, email, date, and subject. It reads from msgfile, cleans the patch by removing email cruft like quoted-printable encoding, trailing whitespace, and excessive context lines, then writes the purified patch to patchfile. Metadata is output to stdout in a format consumable by git-am, including handling of "In-Reply-To" for threading commits.
This command is crucial for applying patches from mailing lists. Typically, it's used after git-mailsplit splits an mbox archive into individual files, allowing git-am to apply them while preserving commit history accurately. It heuristically detects the patch start (often after a line beginning with "---"), strips signatures, and supports charset conversion from various encodings to UTF-8.
Options fine-tune behavior: preserving patch-like subjects, assuming UTF-8, or using scissors to trim excessive context. While robust for standard use cases, it may struggle with malformed emails or unusual formats, making it best for developer mailing lists like LKML.
CAVEATS
Processes only single messages; use git-mailsplit for mboxes.
Charset handling may fail on exotic encodings.
Signatures or attachments can confuse patch detection.
OUTPUT FORMAT
Prints to stdout:
Author: Name <email>
Email: email
Date: Date
Subject: ...
(and others like X-Mailer).
EXAMPLE
git mailinfo incoming.patch meta.txt
Creates clean incoming.patch and prints metadata to meta.txt stdin for piping.
HISTORY
Introduced in Git 1.5.0 (January 2007) by Junio C Hamano to support git-am from mailing lists. Evolved with charset support and scissors in later versions (e.g., 1.7.x), becoming stable for LKML-style patches.
SEE ALSO
git-am(1), git-mailsplit(1), git-apply(1), git-format-patch(1)


