Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Plumbing Commands

git mailinfo command

Reference for git mailinfo: split one patch email into author, subject, date, message body and patch, with -k, -b, -u, --scissors and -m explained.

git mailinfo takes a single email message that contains a patch and splits it into three parts: the metadata (author, email address, subject, date), the commit message, and the patch. The metadata is printed on standard output; the message and the patch go to the two files whose names you pass as arguments.

It is the parser inside git am. You rarely need it directly, but it is useful for tools that import patches from a mailing list, and it explains exactly how Git turns [PATCH] subjects and --- separators into commit data.

Terminal
git mailinfo <msg-file> <patch-file> < email.txt

Try it

Bash Split a patch email

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Subject cleanup options

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git mailinfo [-k | -b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors]
             [-m | --message-id] <msg> <patch> < <mail>
Name Description
<msg> File that receives the commit message (the email body before the patch).
<patch> File that receives the patch (the part starting at --- or the first diff).
-k Keep the subject untouched: do not strip [PATCH], Re: or other prefixes.
-b Strip only bracketed prefixes that contain PATCH, and keep other bracketed text such as [RFC] (the default removes every leading bracketed prefix).
-u Re-encode the message to UTF-8. This is the default.
--encoding=<enc> Re-encode to another character set instead of UTF-8.
-n Disable all re-encoding.
--scissors Drop everything above a "scissors" line (-- >8 -- or similar) and use what follows as the message.
--no-scissors Do not treat scissors lines specially.
-m, --message-id Append the Message-ID header to the commit message.

Output (stdout): Author:, Email:, Subject: and Date: lines. The values come from the From, Subject and Date headers of the email.

Exit status: 0 on success; nonzero if the input cannot be parsed or a file cannot be written.

Usage notes

  • One message per call. mailinfo handles a single email. git mailsplit first divides an mbox into numbered files, and git am combines both steps.
  • Where the patch begins. Text after the first --- line, or the first line that starts a diff, belongs to the patch file. Everything before it, minus the headers, is the message.
  • The message is cleaned. The default strips Re: and leading bracketed prefixes from the subject, joins folded header lines and decodes MIME-encoded words. Use -k to see the raw subject.
  • MIME mail. Quoted-printable and base64 text is decoded, and MIME-encoded header words are converted to UTF-8 unless you pass -n.
  • Watch the spacing with -b. Removing a prefix may leave the next bracket glued to the title, as the example shows; check the subject before committing.
  • No Git repository needed. The command only parses text, so you can run it anywhere, but git am is the tool that creates commits from the result.