Progress:
TIER 2 · MODULE 51· Intermediate

git mailinfo

Used by git am internally.

🎯 What & why

Parses a single email patch (the kind git format-patch produces) into a clean message + diff. It's the lower-level tool that git am uses internally.

🧠 Mental model

Input: one email (mbox-ish). Output: a cleaned commit message on stdout plus a separate patch file. Headers like From:, Subject:, Date: are extracted into a key-value info file.

🛠️ Synopsis

git mailinfo [-k|-b] [-u|--encoding=<enc>|-n] [--[no-]scissors] [--quoted-cr=<action>]
             <msg> <patch>

# Reads RFC822 email from stdin, writes:
#   <msg>   - cleaned commit message body
#   <patch> - the diff portion
# stdout:   - "Author: ...", "Email: ...", "Subject: ...", "Date: ..."

cat 0001-fix.patch | git mailinfo msg.out patch.out

🎚️ Switches & options

FlagWhat it does
-kKeep subject as-is; don't strip [PATCH]/Re: prefixes
-bLike -k but only keep [bracketed] strings that aren't [PATCH]
-uRe-encode commit message to UTF-8 (default)
-nDisable charset re-encoding entirely
-mCopy the message ID into a Message-Id: trailer
--scissorsCut everything before a >8 scissors line; useful when reviewers paste discussion above the patch
--no-scissorsDisable scissors handling (the default)

💡 Use cases

🧪 Examples

Basic split
git mailinfo msg patch < 0001-fix.patch
Keep raw subject
git mailinfo -k msg patch < weird-subject.eml
Honor scissors line
git mailinfo --scissors msg patch < review-thread.eml
No re-encoding
git mailinfo -n msg patch < latin1.eml

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.