table of contents
GIT-FORMAT-PATCH(1) | Git Manual | GIT-FORMAT-PATCH(1) |
NAME¶
git-format-patch - Prepare patches for e-mail submission
SYNOPSIS¶
git format-patch [-k] [(-o|--output-directory) <dir> | --stdout]
[--no-thread | --thread[=<style>]]
[(--attach|--inline)[=<boundary>] | --no-attach]
[-s | --signoff]
[--signature=<signature> | --no-signature]
[-n | --numbered | -N | --no-numbered]
[--start-number <n>] [--numbered-files]
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
[--ignore-if-in-upstream]
[--subject-prefix=Subject-Prefix] [(--reroll-count|-v) <n>]
[--to=<email>] [--cc=<email>]
[--[no-]cover-letter] [--quiet] [--notes[=<ref>]]
[<common diff options>]
[ <since> | <revision range> ]
DESCRIPTION¶
Prepare each commit with its patch in one file per commit, formatted to resemble UNIX mailbox format. The output of this command is convenient for e-mail submission or for use with git am.
There are two ways to specify which commits to operate on.
The first rule takes precedence in the case of a single <commit>. To apply the second rule, i.e., format everything since the beginning of history up until <commit>, use the --root option: git format-patch --root <commit>. If you want to format only <commit> itself, you can do this with git format-patch -1 <commit>.
By default, each output file is numbered sequentially from 1, and uses the first line of the commit message (massaged for pathname safety) as the filename. With the --numbered-files option, the output file names will only be numbers, without the first line of the commit appended. The names of the output files are printed to standard output, unless the --stdout option is specified.
If -o is specified, output files are created in <dir>. Otherwise they are created in the current working directory.
By default, the subject of a single patch is "[PATCH] " followed by the concatenation of lines from the commit message up to the first blank line (see the DISCUSSION section of git-commit(1)).
When multiple patches are output, the subject prefix will instead be "[PATCH n/m] ". To force 1/1 to be added for a single patch, use -n. To omit patch numbers from the subject, use -N.
If given --thread, git-format-patch will generate In-Reply-To and References headers to make the second and subsequent patch mails appear as replies to the first mail; this also generates a Message-Id header to reference.
OPTIONS¶
-p, --no-stat
-U<n>, --unified=<n>
--minimal
--patience
--histogram
--diff-algorithm={patience|minimal|histogram|myers}
default, myers
minimal
patience
histogram
For instance, if you configured diff.algorithm variable to a non-default value and want to use the default one, then you have to use --diff-algorithm=default option.
--stat[=<width>[,<name-width>[,<count>]]]
These parameters can also be set individually with --stat-width=<width>, --stat-name-width=<name-width> and --stat-count=<count>.
--numstat
--shortstat
--dirstat[=<param1,param2,...>]
changes
lines
files
cumulative
<limit>
Example: The following will count changed files, while ignoring directories with less than 10% of the total amount of changed files, and accumulating child directory counts in the parent directories: --dirstat=files,10,cumulative.
--summary
--no-renames
--full-index
--binary
--abbrev[=<n>]
-B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
It affects the way a change that amounts to a total rewrite of a file not as a series of deletion and insertion mixed together with a very few lines that happen to match textually as the context, but as a single deletion of everything old followed by a single insertion of everything new, and the number m controls this aspect of the -B option (defaults to 60%). -B/70% specifies that less than 30% of the original should remain in the result for Git to consider it a total rewrite (i.e. otherwise the resulting patch will be a series of deletion and insertion mixed together with context lines).
When used with -M, a totally-rewritten file is also considered as the source of a rename (usually -M only considers a file that disappeared as the source of a rename), and the number n controls this aspect of the -B option (defaults to 50%). -B20% specifies that a change with addition and deletion compared to 20% or more of the file’s size are eligible for being picked up as a possible source of a rename to another file.
-M[<n>], --find-renames[=<n>]
-C[<n>], --find-copies[=<n>]
--find-copies-harder
-D, --irreversible-delete
When used together with -B, omit also the preimage in the deletion part of a delete/create pair.
-l<num>
-O<orderfile>
-a, --text
--ignore-space-at-eol
-b, --ignore-space-change
-w, --ignore-all-space
--inter-hunk-context=<lines>
-W, --function-context
--ext-diff
--no-ext-diff
--textconv, --no-textconv
--ignore-submodules[=<when>]
--src-prefix=<prefix>
--dst-prefix=<prefix>
--no-prefix
For more detailed explanation on these common options, see also gitdiffcore(7).
-<n>
-o <dir>, --output-directory <dir>
-n, --numbered
-N, --no-numbered
--start-number <n>
--numbered-files
-k, --keep-subject
-s, --signoff
--stdout
--attach[=<boundary>]
--no-attach
--inline[=<boundary>]
--thread[=<style>], --no-thread
The optional <style> argument can be either shallow or deep. shallow threading makes every mail a reply to the head of the series, where the head is chosen from the cover letter, the --in-reply-to, and the first patch mail, in this order. deep threading makes every mail a reply to the previous one.
The default is --no-thread, unless the format.thread configuration is set. If --thread is specified without a style, it defaults to the style specified by format.thread if any, or else shallow.
Beware that the default for git send-email is to thread emails itself. If you want git format-patch to take care of threading, you will want to ensure that threading is disabled for git send-email.
--in-reply-to=Message-Id
--ignore-if-in-upstream
--subject-prefix=<Subject-Prefix>
-v <n>, --reroll-count=<n>
--to=<email>
--cc=<email>
--add-header=<header>
--[no-]cover-letter
--notes[=<ref>]
The expected use case of this is to write supporting explanation for the commit that does not belong to the commit log message proper, and include it with the patch submission. While one can simply write these explanations after format-patch has run but before sending, keeping them as Git notes allows them to be maintained between versions of the patch series (but see the discussion of the notes.rewrite configuration options in git-notes(1) to use this workflow).
--[no]-signature=<signature>
--suffix=.<sfx>
Note that the leading character does not have to be a dot; for example, you can use --suffix=-patch to get 0001-description-of-my-change-patch.
--quiet
--no-binary
--root
CONFIGURATION¶
You can specify extra mail header lines to be added to each message, defaults for the subject prefix and file suffix, number patches when outputting more than one patch, add "To" or "Cc:" headers, configure attachments, and sign off patches with configuration variables.
[format]
headers = "Organization: git-foo\n"
subjectprefix = CHANGE
suffix = .txt
numbered = auto
to = <email>
cc = <email>
attach [ = mime-boundary-string ]
signoff = true
coverletter = auto
DISCUSSION¶
The patch produced by git format-patch is in UNIX mailbox format, with a fixed "magic" time stamp to indicate that the file is output from format-patch rather than a real mailbox, like so:
From 8f72bad1baf19a53459661343e21d6491c3908d3 Mon Sep 17 00:00:00 2001 From: Tony Luck <tony.luck@intel.com> Date: Tue, 13 Jul 2010 11:42:54 -0700 Subject: [PATCH] =?UTF-8?q?[IA64]=20Put=20ia64=20config=20files=20on=20the=20?=
=?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20diet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit arch/arm config files were slimmed down using a python script (See commit c2330e286f68f1c408b4aa6515ba49d57f05beae comment) Do the same for ia64 so we can have sleek & trim looking ...
Typically it will be placed in a MUA’s drafts folder, edited to add timely commentary that should not go in the changelog after the three dashes, and then sent as a message whose body, in our example, starts with "arch/arm config files were...". On the receiving end, readers can save interesting patches in a UNIX mailbox and apply them with git-am(1).
When a patch is part of an ongoing discussion, the patch generated by git format-patch can be tweaked to take advantage of the git am --scissors feature. After your response to the discussion comes a line that consists solely of "-- >8 --" (scissors and perforation), followed by the patch with unnecessary header fields removed:
... > So we should do such-and-such. Makes sense to me. How about this patch? -- >8 -- Subject: [IA64] Put ia64 config files on the Uwe Kleine-König diet arch/arm config files were slimmed down using a python script ...
When sending a patch this way, most often you are sending your own patch, so in addition to the "From $SHA1 $magic_timestamp" marker you should omit From: and Date: lines from the patch file. The patch title is likely to be different from the subject of the discussion the patch is in response to, so it is likely that you would want to keep the Subject: line, like the example above.
Checking for patch corruption¶
Many mailers if not set up properly will corrupt whitespace. Here are two common types of corruption:
One way to test if your MUA is set up correctly is:
$ git fetch <project> master:test-apply $ git checkout test-apply $ git reset --hard $ git am a.patch
If it does not apply correctly, there can be various reasons.
MUA-SPECIFIC HINTS¶
Here are some hints on how to successfully submit patches inline using various mailers.
GMail¶
GMail does not have any way to turn off line wrapping in the web interface, so it will mangle any emails that you send. You can however use "git send-email" and send your patches through the GMail SMTP server, or use any IMAP email client to connect to the google IMAP server and forward the emails through that.
For hints on using git send-email to send your patches through the GMail SMTP server, see the EXAMPLE section of git-send-email(1).
For hints on submission using the IMAP interface, see the EXAMPLE section of git-imap-send(1).
Thunderbird¶
By default, Thunderbird will both wrap emails as well as flag them as being format=flowed, both of which will make the resulting email unusable by Git.
There are three different approaches: use an add-on to turn off line wraps, configure Thunderbird to not mangle patches, or use an external editor to keep Thunderbird from mangling the patches.
Approach #1 (add-on)
Install the Toggle Word Wrap add-on that is available from https://addons.mozilla.org/thunderbird/addon/toggle-word-wrap/ It adds a menu entry "Enable Word Wrap" in the composer’s "Options" menu that you can tick off. Now you can compose the message as you otherwise do (cut + paste, git format-patch | git imap-send, etc), but you have to insert line breaks manually in any text that you type.
Approach #2 (configuration)
Three steps:
In Thunderbird 2: Edit..Preferences..Composition, wrap plain text messages at 0
In Thunderbird 3: Edit..Preferences..Advanced..Config Editor. Search for "mail.wrap_long_lines". Toggle it to make sure it is set to false.
After that is done, you should be able to compose email as you otherwise would (cut + paste, git format-patch | git imap-send, etc), and the patches will not be mangled.
Approach #3 (external editor)
The following Thunderbird extensions are needed: AboutConfig from http://aboutconfig.mozdev.org/ and External Editor from http://globs.org/articles.php?lng=en&pg=8
mailnews.send_plaintext_flowed => false
mailnews.wraplength => 0
Side note: it may be possible to do step 2 with about:config and the following settings but no one’s tried yet.
mail.html_compose => false
mail.identity.default.compose_html => false
mail.identity.id?.compose_html => false
There is a script in contrib/thunderbird-patch-inline which can help you include patches with Thunderbird in an easy way. To use it, do the steps above and then use the script as the external editor.
KMail¶
This should help you to submit patches inline using KMail.
EXAMPLES¶
$ git format-patch -k --stdout R1..R2 | git am -3 -k
$ git format-patch origin
For each commit a separate file is created in the current directory.
$ git format-patch --root origin
$ git format-patch -M -B origin
Additionally, it detects and handles renames and complete rewrites intelligently to produce a renaming patch. A renaming patch reduces the amount of text output, and generally makes it easier to review. Note that non-Git "patch" programs won’t understand renaming patches, so use it only when you know the recipient uses Git to apply your patch.
$ git format-patch -3
SEE ALSO¶
GIT¶
Part of the git(1) suite
05/23/2023 | Git 1.8.3.1 |