blob: 0f81d0437bb65bd0ee68ef63edf7bb48d9ea87a6 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-format-patch(1)
2===================
3
4NAME
5----
Junio C Hamano01078922006-03-10 00:31:476git-format-patch - Prepare patches for e-mail submission
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano235a91e2006-01-07 01:13:5811[verse]
Junio C Hamanof4581102009-04-25 08:29:5912'git format-patch' [-k] [(-o|--output-directory) <dir> | --stdout]
Junio C Hamano1bbd0f42009-07-23 06:20:2913 [--no-thread | --thread[=<style>]]
Junio C Hamanof4581102009-04-25 08:29:5914 [(--attach|--inline)[=<boundary>] | --no-attach]
15 [-s | --signoff]
Junio C Hamano89a57342010-06-22 23:22:5516 [--signature=<signature> | --no-signature]
Junio C Hamanoc8c398a2014-06-16 21:14:0517 [--signature-file=<file>]
Junio C Hamano24bc09a2008-02-28 00:27:4418 [-n | --numbered | -N | --no-numbered]
19 [--start-number <n>] [--numbered-files]
Junio C Hamanoa8858312019-09-30 05:07:4520 [--in-reply-to=<message id>] [--suffix=.<sfx>]
Junio C Hamano24bc09a2008-02-28 00:27:4421 [--ignore-if-in-upstream]
Junio C Hamano8ac8a3d2019-11-11 04:33:4622 [--cover-from-description=<mode>]
Junio C Hamanoa8858312019-09-30 05:07:4523 [--rfc] [--subject-prefix=<subject prefix>]
Junio C Hamanoad70bf02016-09-26 23:44:2724 [(--reroll-count|-v) <n>]
Junio C Hamanoea90ab32010-03-15 20:32:5525 [--to=<email>] [--cc=<email>]
Junio C Hamano51937872019-06-13 22:09:3026 [--[no-]cover-letter] [--quiet]
Junio C Hamano67bf2242020-04-22 21:41:4427 [--[no-]encode-email-headers]
Junio C Hamano51937872019-06-13 22:09:3028 [--no-notes | --notes[=<ref>]]
Junio C Hamano980e61e2018-09-17 22:45:5229 [--interdiff=<previous>]
30 [--range-diff=<previous> [--creation-factor=<percent>]]
Junio C Hamanoa4ff7292017-08-23 21:56:4331 [--progress]
Junio C Hamanof4581102009-04-25 08:29:5932 [<common diff options>]
Junio C Hamano7d9e9bd2007-08-29 07:31:4733 [ <since> | <revision range> ]
Junio C Hamano1a4e8412005-12-27 08:17:2334
35DESCRIPTION
36-----------
Junio C Hamano341071d2006-06-04 07:24:4837
Junio C Hamano7d9e9bd2007-08-29 07:31:4738Prepare each commit with its patch in
Junio C Hamano341071d2006-06-04 07:24:4839one file per commit, formatted to resemble UNIX mailbox format.
Junio C Hamano341071d2006-06-04 07:24:4840The output of this command is convenient for e-mail submission or
Junio C Hamano1aa40d22010-01-21 17:46:4341for use with 'git am'.
Junio C Hamano1a4e8412005-12-27 08:17:2342
Junio C Hamano7d9e9bd2007-08-29 07:31:4743There are two ways to specify which commits to operate on.
44
451. A single commit, <since>, specifies that the commits leading
46 to the tip of the current branch that are not in the history
47 that leads to the <since> to be output.
48
492. Generic <revision range> expression (see "SPECIFYING
Junio C Hamanoc27b7332010-10-14 04:37:2850 REVISIONS" section in linkgit:gitrevisions[7]) means the
Junio C Hamano7d9e9bd2007-08-29 07:31:4751 commits in the specified range.
52
Junio C Hamano9572e922009-04-02 06:52:0353The first rule takes precedence in the case of a single <commit>. To
54apply the second rule, i.e., format everything since the beginning of
Junio C Hamanoccb82522018-05-08 07:52:0955history up until <commit>, use the `--root` option: `git format-patch
Junio C Hamanob76a6862012-05-02 22:02:4656--root <commit>`. If you want to format only <commit> itself, you
Junio C Hamano3b70d3c2009-11-21 17:37:3757can do this with `git format-patch -1 <commit>`.
Junio C Hamano7d9e9bd2007-08-29 07:31:4758
Junio C Hamano94cad1a2007-06-06 10:48:2559By default, each output file is numbered sequentially from 1, and uses the
Junio C Hamano341071d2006-06-04 07:24:4860first line of the commit message (massaged for pathname safety) as
Junio C Hamano3b70d3c2009-11-21 17:37:3761the filename. With the `--numbered-files` option, the output file names
Junio C Hamano94cad1a2007-06-06 10:48:2562will only be numbers, without the first line of the commit appended.
63The names of the output files are printed to standard
Junio C Hamano3b70d3c2009-11-21 17:37:3764output, unless the `--stdout` option is specified.
Junio C Hamano38de0a22006-02-07 10:24:3565
Junio C Hamano3b70d3c2009-11-21 17:37:3766If `-o` is specified, output files are created in <dir>. Otherwise
Junio C Hamano289d7e82016-01-27 00:20:3867they are created in the current working directory. The default path
Junio C Hamano042f2142016-06-27 18:05:0568can be set with the `format.outputDirectory` configuration option.
Junio C Hamano289d7e82016-01-27 00:20:3869The `-o` option takes precedence over `format.outputDirectory`.
70To store patches in the current working directory even when
Junio C Hamanod52ae632019-10-23 05:33:3171`format.outputDirectory` points elsewhere, use `-o .`. All directory
72components will be created.
Junio C Hamano1a4e8412005-12-27 08:17:2373
Junio C Hamano281fd392012-09-17 23:57:4174By default, the subject of a single patch is "[PATCH] " followed by
75the concatenation of lines from the commit message up to the first blank
76line (see the DISCUSSION section of linkgit:git-commit[1]).
77
78When multiple patches are output, the subject prefix will instead be
79"[PATCH n/m] ". To force 1/1 to be added for a single patch, use `-n`.
80To omit patch numbers from the subject, use `-N`.
Junio C Hamano1a4e8412005-12-27 08:17:2381
Junio C Hamano3b70d3c2009-11-21 17:37:3782If given `--thread`, `git-format-patch` will generate `In-Reply-To` and
83`References` headers to make the second and subsequent patch mails appear
84as replies to the first mail; this also generates a `Message-Id` header to
Junio C Hamanof9ca97d2006-07-25 22:23:0985reference.
Junio C Hamano1a4e8412005-12-27 08:17:2386
87OPTIONS
88-------
Junio C Hamanoff979792007-11-16 10:11:3089:git-format-patch: 1
Junio C Hamano60f8aa82007-03-06 09:58:2690include::diff-options.txt[]
91
Junio C Hamanobb0f4042007-07-04 06:41:4092-<n>::
Junio C Hamano3b4609d2010-09-30 00:04:3493Prepare patches from the topmost <n> commits.
Junio C Hamanobb0f4042007-07-04 06:41:4094
Junio C Hamanoeb415992008-06-08 22:49:4795-o <dir>::
96--output-directory <dir>::
Junio C Hamano1a4e8412005-12-27 08:17:2397Use <dir> to store the resulting files, instead of the
Junio C Hamano1bab4b02006-06-06 21:58:3398current working directory.
Junio C Hamano1a4e8412005-12-27 08:17:2399
Junio C Hamanoeb415992008-06-08 22:49:47100-n::
101--numbered::
Junio C Hamano7d06a8a2008-10-20 05:42:33102Name output in '[PATCH n/m]' format, even with a single patch.
Junio C Hamano1a4e8412005-12-27 08:17:23103
Junio C Hamanoeb415992008-06-08 22:49:47104-N::
105--no-numbered::
Junio C Hamano8c5802d2007-11-15 00:13:36106Name output in '[PATCH]' format.
107
Junio C Hamano341071d2006-06-04 07:24:48108--start-number <n>::
109Start numbering the patches at <n> instead of 1.
110
Junio C Hamano94cad1a2007-06-06 10:48:25111--numbered-files::
112Output file names will be a simple number sequence
113without the default first line of the commit appended.
Junio C Hamano94cad1a2007-06-06 10:48:25114
Junio C Hamanoeb415992008-06-08 22:49:47115-k::
116--keep-subject::
Junio C Hamano1a4e8412005-12-27 08:17:23117Do not strip/add '[PATCH]' from the first line of the
118commit log message.
119
Junio C Hamanoeb415992008-06-08 22:49:47120-s::
121--signoff::
Junio C Hamano1a4e8412005-12-27 08:17:23122Add `Signed-off-by:` line to the commit message, using
123the committer identity of yourself.
Junio C Hamano4e6ba272016-01-20 23:23:19124See the signoff option in linkgit:git-commit[1] for more information.
Junio C Hamano1a4e8412005-12-27 08:17:23125
Junio C Hamano1a4e8412005-12-27 08:17:23126--stdout::
Junio C Hamano341071d2006-06-04 07:24:48127Print all commits to the standard output in mbox format,
128instead of creating a file for each one.
Junio C Hamano1a4e8412005-12-27 08:17:23129
Junio C Hamanoc51fede2007-03-12 07:29:20130--attach[=<boundary>]::
131Create multipart/mixed attachment, the first part of
132which is the commit message and the patch itself in the
Junio C Hamano3b70d3c2009-11-21 17:37:37133second part, with `Content-Disposition: attachment`.
Junio C Hamanoc51fede2007-03-12 07:29:20134
Junio C Hamano0a235222009-03-06 08:21:09135--no-attach::
136Disable the creation of an attachment, overriding the
137configuration setting.
138
Junio C Hamanoc51fede2007-03-12 07:29:20139--inline[=<boundary>]::
140Create multipart/mixed attachment, the first part of
141which is the commit message and the patch itself in the
Junio C Hamano3b70d3c2009-11-21 17:37:37142second part, with `Content-Disposition: inline`.
Junio C Hamano2496ae42006-03-11 08:04:33143
Junio C Hamanoea6a7642009-03-11 23:56:19144--thread[=<style>]::
Junio C Hamano1bbd0f42009-07-23 06:20:29145--no-thread::
Junio C Hamano3b70d3c2009-11-21 17:37:37146Controls addition of `In-Reply-To` and `References` headers to
Junio C Hamano1bbd0f42009-07-23 06:20:29147make the second and subsequent mails appear as replies to the
Junio C Hamano3b70d3c2009-11-21 17:37:37148first. Also controls generation of the `Message-Id` header to
Junio C Hamano1bbd0f42009-07-23 06:20:29149reference.
Junio C Hamanoea6a7642009-03-11 23:56:19150+
151The optional <style> argument can be either `shallow` or `deep`.
Junio C Hamanof4581102009-04-25 08:29:59152'shallow' threading makes every mail a reply to the head of the
Junio C Hamanoea6a7642009-03-11 23:56:19153series, where the head is chosen from the cover letter, the
Junio C Hamanob76a6862012-05-02 22:02:46154`--in-reply-to`, and the first patch mail, in this order. 'deep'
Junio C Hamano1bbd0f42009-07-23 06:20:29155threading makes every mail a reply to the previous one.
156+
Junio C Hamano042f2142016-06-27 18:05:05157The default is `--no-thread`, unless the `format.thread` configuration
Junio C Hamano3b70d3c2009-11-21 17:37:37158is set. If `--thread` is specified without a style, it defaults to the
Junio C Hamano042f2142016-06-27 18:05:05159style specified by `format.thread` if any, or else `shallow`.
Junio C Hamano1bbd0f42009-07-23 06:20:29160+
161Beware that the default for 'git send-email' is to thread emails
Junio C Hamano3b70d3c2009-11-21 17:37:37162itself. If you want `git format-patch` to take care of threading, you
163will want to ensure that threading is disabled for `git send-email`.
Junio C Hamanof9ca97d2006-07-25 22:23:09164
Junio C Hamanoa8858312019-09-30 05:07:45165--in-reply-to=<message id>::
Junio C Hamano3b70d3c2009-11-21 17:37:37166Make the first mail (or all the mails with `--no-thread`) appear as a
Junio C Hamanoa8858312019-09-30 05:07:45167reply to the given <message id>, which avoids breaking threads to
Junio C Hamanof9ca97d2006-07-25 22:23:09168provide a new patch series.
Junio C Hamano2496ae42006-03-11 08:04:33169
Junio C Hamano7c73c662007-01-19 00:37:50170--ignore-if-in-upstream::
171Do not include a patch that matches a commit in
172<until>..<since>. This will examine all patches reachable
173from <since> but not from <until> and compare them with the
174patches being generated, and any patch that matches is
175ignored.
176
Junio C Hamano8ac8a3d2019-11-11 04:33:46177--cover-from-description=<mode>::
178Controls which parts of the cover letter will be automatically
179populated using the branch's description.
180+
181If `<mode>` is `message` or `default`, the cover letter subject will be
182populated with placeholder text. The body of the cover letter will be
183populated with the branch's description. This is the default mode when
184no configuration nor command line option is specified.
185+
186If `<mode>` is `subject`, the first paragraph of the branch description will
187populate the cover letter subject. The remainder of the description will
188populate the body of the cover letter.
189+
190If `<mode>` is `auto`, if the first paragraph of the branch description
191is greater than 100 bytes, then the mode will be `message`, otherwise
192`subject` will be used.
193+
194If `<mode>` is `none`, both the cover letter subject and body will be
195populated with placeholder text.
196
Junio C Hamanoa8858312019-09-30 05:07:45197--subject-prefix=<subject prefix>::
Junio C Hamano6f1cca82007-04-12 05:02:47198Instead of the standard '[PATCH]' prefix in the subject
Junio C Hamanoa8858312019-09-30 05:07:45199line, instead use '[<subject prefix>]'. This
Junio C Hamano6f1cca82007-04-12 05:02:47200allows for useful naming of a patch series, and can be
Junio C Hamano3b70d3c2009-11-21 17:37:37201combined with the `--numbered` option.
Junio C Hamano6f1cca82007-04-12 05:02:47202
Junio C Hamanoad70bf02016-09-26 23:44:27203--rfc::
204Alias for `--subject-prefix="RFC PATCH"`. RFC means "Request For
205Comments"; use this when sending an experimental patch for
206discussion rather than application.
207
Junio C Hamano7dac6902013-01-12 08:25:31208-v <n>::
209--reroll-count=<n>::
210Mark the series as the <n>-th iteration of the topic. The
Junio C Hamanodf5384b2015-06-24 21:12:12211output filenames have `v<n>` prepended to them, and the
Junio C Hamano7dac6902013-01-12 08:25:31212subject prefix ("PATCH" by default, but configurable via the
213`--subject-prefix` option) has ` v<n>` appended to it. E.g.
214`--reroll-count=4` may produce `v4-0001-add-makefile.patch`
215file that has "Subject: [PATCH v4 1/20] Add makefile" in it.
216
Junio C Hamanoea90ab32010-03-15 20:32:55217--to=<email>::
218Add a `To:` header to the email headers. This is in addition
219to any configured headers, and may be used multiple times.
Junio C Hamano7bd050f2011-09-22 06:32:22220The negated form `--no-to` discards all `To:` headers added so
221far (from config or command line).
Junio C Hamanoea90ab32010-03-15 20:32:55222
Junio C Hamano24bc09a2008-02-28 00:27:44223--cc=<email>::
Junio C Hamano3b70d3c2009-11-21 17:37:37224Add a `Cc:` header to the email headers. This is in addition
Junio C Hamano24bc09a2008-02-28 00:27:44225to any configured headers, and may be used multiple times.
Junio C Hamano7bd050f2011-09-22 06:32:22226The negated form `--no-cc` discards all `Cc:` headers added so
227far (from config or command line).
Junio C Hamano24bc09a2008-02-28 00:27:44228
Junio C Hamanoededf2b2013-07-15 21:11:16229--from::
230--from=<ident>::
231Use `ident` in the `From:` header of each commit email. If the
232author ident of the commit is not textually identical to the
233provided `ident`, place a `From:` header in the body of the
234message with the original author. If no `ident` is given, use
235the committer ident.
236+
237Note that this option is only useful if you are actually sending the
238emails and want to identify yourself as the sender, but retain the
239original author (and `git am` will correctly pick up the in-body
240header). Note also that `git send-email` already handles this
241transformation for you, and this option should not be used if you are
242feeding the result to `git send-email`.
243
Junio C Hamano9572e922009-04-02 06:52:03244--add-header=<header>::
245Add an arbitrary header to the email headers. This is in addition
246to any configured headers, and may be used multiple times.
Junio C Hamano7bd050f2011-09-22 06:32:22247For example, `--add-header="Organization: git-foo"`.
248The negated form `--no-add-header` discards *all* (`To:`,
249`Cc:`, and custom) headers added so far from config or command
250line.
Junio C Hamano9572e922009-04-02 06:52:03251
Junio C Hamanoea3b7522013-04-18 19:37:53252--[no-]cover-letter::
Junio C Hamano92a4abd2008-08-15 05:34:44253In addition to the patches, generate a cover letter file
Junio C Hamano7db630e2015-09-17 20:26:22254containing the branch description, shortlog and the overall diffstat. You can
Junio C Hamano92a4abd2008-08-15 05:34:44255fill in a description in the file before sending it out.
Junio C Hamano24bc09a2008-02-28 00:27:44256
Junio C Hamano67bf2242020-04-22 21:41:44257--encode-email-headers::
258--no-encode-email-headers::
259Encode email headers that have non-ASCII characters with
260"Q-encoding" (described in RFC 2047), instead of outputting the
261headers verbatim. Defaults to the value of the
262`format.encodeEmailHeaders` configuration variable.
263
Junio C Hamano980e61e2018-09-17 22:45:52264--interdiff=<previous>::
265As a reviewer aid, insert an interdiff into the cover letter,
266or as commentary of the lone patch of a 1-patch series, showing
267the differences between the previous version of the patch series and
268the series currently being formatted. `previous` is a single revision
269naming the tip of the previous series which shares a common base with
270the series being formatted (for example `git format-patch
271--cover-letter --interdiff=feature/v1 -3 feature/v2`).
272
273--range-diff=<previous>::
274As a reviewer aid, insert a range-diff (see linkgit:git-range-diff[1])
275into the cover letter, or as commentary of the lone patch of a
2761-patch series, showing the differences between the previous
277version of the patch series and the series currently being formatted.
278`previous` can be a single revision naming the tip of the previous
279series if it shares a common base with the series being formatted (for
280example `git format-patch --cover-letter --range-diff=feature/v1 -3
281feature/v2`), or a revision range if the two versions of the series are
282disjoint (for example `git format-patch --cover-letter
283--range-diff=feature/v1~3..feature/v1 -3 feature/v2`).
Junio C Hamanof2b280b2018-12-01 14:45:01284+
285Note that diff options passed to the command affect how the primary
286product of `format-patch` is generated, and they are not passed to
287the underlying `range-diff` machinery used to generate the cover-letter
288material (this may change in the future).
Junio C Hamano980e61e2018-09-17 22:45:52289
290--creation-factor=<percent>::
291Used with `--range-diff`, tweak the heuristic which matches up commits
292between the previous and current series of patches by adjusting the
293creation/deletion cost fudge factor. See linkgit:git-range-diff[1])
294for details.
295
Junio C Hamano4eb2b9c2012-11-15 21:12:29296--notes[=<ref>]::
Junio C Hamano51937872019-06-13 22:09:30297--no-notes::
Junio C Hamano4eb2b9c2012-11-15 21:12:29298Append the notes (see linkgit:git-notes[1]) for the commit
299after the three-dash line.
300+
301The expected use case of this is to write supporting explanation for
302the commit that does not belong to the commit log message proper,
303and include it with the patch submission. While one can simply write
304these explanations after `format-patch` has run but before sending,
Junio C Hamano076ffcc2013-02-06 05:13:21305keeping them as Git notes allows them to be maintained between versions
Junio C Hamano4eb2b9c2012-11-15 21:12:29306of the patch series (but see the discussion of the `notes.rewrite`
307configuration options in linkgit:git-notes[1] to use this workflow).
Junio C Hamano51937872019-06-13 22:09:30308+
309The default is `--no-notes`, unless the `format.notes` configuration is
310set.
Junio C Hamano4eb2b9c2012-11-15 21:12:29311
Junio C Hamanocb06ef92017-03-21 22:40:14312--[no-]signature=<signature>::
Junio C Hamano89a57342010-06-22 23:22:55313Add a signature to each message produced. Per RFC 3676 the signature
314is separated from the body by a line with '-- ' on it. If the
Junio C Hamano076ffcc2013-02-06 05:13:21315signature option is omitted the signature defaults to the Git version
Junio C Hamano89a57342010-06-22 23:22:55316number.
317
Junio C Hamanoc8c398a2014-06-16 21:14:05318--signature-file=<file>::
319Works just like --signature except the signature is read from a file.
320
Junio C Hamano4f9a6052007-01-17 20:25:16321--suffix=.<sfx>::
Junio C Hamano7c73c662007-01-19 00:37:50322Instead of using `.patch` as the suffix for generated
Junio C Hamanoa6387422007-08-25 03:54:27323filenames, use specified suffix. A common alternative is
Junio C Hamanof4581102009-04-25 08:29:59324`--suffix=.txt`. Leaving this empty will remove the `.patch`
325suffix.
Junio C Hamano4f9a6052007-01-17 20:25:16326+
Junio C Hamanof4581102009-04-25 08:29:59327Note that the leading character does not have to be a dot; for example,
328you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
Junio C Hamano4f9a6052007-01-17 20:25:16329
Junio C Hamano535ed7a2013-09-04 20:35:57330-q::
Junio C Hamano209ebe82011-04-27 21:09:59331--quiet::
332Do not print the names of the generated files to standard output.
333
Junio C Hamano869bb802008-05-12 00:29:47334--no-binary::
Junio C Hamanof4581102009-04-25 08:29:59335Do not output contents of changes in binary files, instead
336display a notice that those files changed. Patches generated
337using this option cannot be applied properly, but they are
338still useful for code review.
Junio C Hamano869bb802008-05-12 00:29:47339
Junio C Hamano409a33a2015-12-22 23:45:23340--zero-commit::
341 Output an all-zero hash in each patch's From header instead
342 of the hash of the commit.
343
Junio C Hamano2267da52019-12-18 23:09:43344--[no-]base[=<commit>]::
Junio C Hamanof2a3a752016-05-23 22:54:39345Record the base tree information to identify the state the
346patch series applies to. See the BASE TREE INFORMATION section
Junio C Hamanoa8858312019-09-30 05:07:45347below for details. If <commit> is "auto", a base commit is
Junio C Hamano2267da52019-12-18 23:09:43348automatically chosen. The `--no-base` option overrides a
349`format.useAutoBase` configuration.
Junio C Hamanof2a3a752016-05-23 22:54:39350
Junio C Hamano9572e922009-04-02 06:52:03351--root::
352Treat the revision argument as a <revision range>, even if it
353is just a single commit (that would normally be treated as a
354<since>). Note that root commits included in the specified
355range are always formatted as creation patches, independently
356of this flag.
357
Junio C Hamanoa4ff7292017-08-23 21:56:43358--progress::
359Show progress reports on stderr as patches are generated.
360
Junio C Hamano2496ae42006-03-11 08:04:33361CONFIGURATION
362-------------
Junio C Hamanof4581102009-04-25 08:29:59363You can specify extra mail header lines to be added to each message,
364defaults for the subject prefix and file suffix, number patches when
Junio C Hamanoa8858312019-09-30 05:07:45365outputting more than one patch, add "To:" or "Cc:" headers, configure
366attachments, change the patch output directory, and sign off patches
367with configuration variables.
Junio C Hamano2496ae42006-03-11 08:04:33368
Junio C Hamano7c73c662007-01-19 00:37:50369------------
Junio C Hamano2496ae42006-03-11 08:04:33370[format]
Junio C Hamanoba4b9282008-07-06 05:20:31371headers = "Organization: git-foo\n"
Junio C Hamano322c6242015-03-23 21:32:46372subjectPrefix = CHANGE
Junio C Hamanoba4b9282008-07-06 05:20:31373suffix = .txt
374numbered = auto
Junio C Hamanoea90ab32010-03-15 20:32:55375to = <email>
Junio C Hamano2fbcd212008-05-14 22:26:07376cc = <email>
Junio C Hamano0a235222009-03-06 08:21:09377attach [ = mime-boundary-string ]
Junio C Hamano322c6242015-03-23 21:32:46378signOff = true
Junio C Hamanoa8858312019-09-30 05:07:45379outputDirectory = <directory>
380coverLetter = auto
Junio C Hamano8ac8a3d2019-11-11 04:33:46381coverFromDescription = auto
Junio C Hamano7c73c662007-01-19 00:37:50382------------
Junio C Hamano4f9a6052007-01-17 20:25:16383
Junio C Hamano1a4e8412005-12-27 08:17:23384
Junio C Hamanob77f8192011-05-05 01:30:38385DISCUSSION
386----------
387
388The patch produced by 'git format-patch' is in UNIX mailbox format,
389with a fixed "magic" time stamp to indicate that the file is output
390from format-patch rather than a real mailbox, like so:
391
392------------
393From 8f72bad1baf19a53459661343e21d6491c3908d3 Mon Sep 17 00:00:00 2001
394From: Tony Luck <tony.luck@intel.com>
395Date: Tue, 13 Jul 2010 11:42:54 -0700
396Subject: [PATCH] =?UTF-8?q?[IA64]=20Put=20ia64=20config=20files=20on=20the=20?=
397 =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20diet?=
398MIME-Version: 1.0
399Content-Type: text/plain; charset=UTF-8
400Content-Transfer-Encoding: 8bit
401
402arch/arm config files were slimmed down using a python script
403(See commit c2330e286f68f1c408b4aa6515ba49d57f05beae comment)
404
405Do the same for ia64 so we can have sleek & trim looking
406...
407------------
408
409Typically it will be placed in a MUA's drafts folder, edited to add
410timely commentary that should not go in the changelog after the three
411dashes, and then sent as a message whose body, in our example, starts
412with "arch/arm config files were...". On the receiving end, readers
413can save interesting patches in a UNIX mailbox and apply them with
414linkgit:git-am[1].
415
416When a patch is part of an ongoing discussion, the patch generated by
417'git format-patch' can be tweaked to take advantage of the 'git am
418--scissors' feature. After your response to the discussion comes a
419line that consists solely of "`-- >8 --`" (scissors and perforation),
420followed by the patch with unnecessary header fields removed:
421
422------------
423...
424> So we should do such-and-such.
425
426Makes sense to me. How about this patch?
427
428-- >8 --
429Subject: [IA64] Put ia64 config files on the Uwe Kleine-König diet
430
431arch/arm config files were slimmed down using a python script
432...
433------------
434
435When sending a patch this way, most often you are sending your own
436patch, so in addition to the "`From $SHA1 $magic_timestamp`" marker you
437should omit `From:` and `Date:` lines from the patch file. The patch
438title is likely to be different from the subject of the discussion the
439patch is in response to, so it is likely that you would want to keep
440the Subject: line, like the example above.
441
442Checking for patch corruption
443~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
444Many mailers if not set up properly will corrupt whitespace. Here are
445two common types of corruption:
446
447* Empty context lines that do not have _any_ whitespace.
448
449* Non-empty context lines that have one extra whitespace at the
450 beginning.
451
452One way to test if your MUA is set up correctly is:
453
454* Send the patch to yourself, exactly the way you would, except
455 with To: and Cc: lines that do not contain the list and
456 maintainer address.
457
458* Save that patch to a file in UNIX mailbox format. Call it a.patch,
459 say.
460
461* Apply it:
462
463 $ git fetch <project> master:test-apply
Junio C Hamanoc9f11c22019-07-10 02:54:04464 $ git switch test-apply
465 $ git restore --source=HEAD --staged --worktree :/
Junio C Hamanob77f8192011-05-05 01:30:38466 $ git am a.patch
467
468If it does not apply correctly, there can be various reasons.
469
470* The patch itself does not apply cleanly. That is _bad_ but
471 does not have much to do with your MUA. You might want to rebase
472 the patch with linkgit:git-rebase[1] before regenerating it in
473 this case.
474
475* The MUA corrupted your patch; "am" would complain that
476 the patch does not apply. Look in the .git/rebase-apply/ subdirectory and
477 see what 'patch' file contains and check for the common
478 corruption patterns mentioned above.
479
480* While at it, check the 'info' and 'final-commit' files as well.
481 If what is in 'final-commit' is not exactly what you would want to
482 see in the commit log message, it is very likely that the
483 receiver would end up hand editing the log message when applying
484 your patch. Things like "Hi, this is my first patch.\n" in the
485 patch e-mail should come after the three-dash line that signals
486 the end of the commit message.
487
488MUA-SPECIFIC HINTS
489------------------
490Here are some hints on how to successfully submit patches inline using
491various mailers.
492
493GMail
494~~~~~
495GMail does not have any way to turn off line wrapping in the web
496interface, so it will mangle any emails that you send. You can however
497use "git send-email" and send your patches through the GMail SMTP server, or
498use any IMAP email client to connect to the google IMAP server and forward
499the emails through that.
500
501For hints on using 'git send-email' to send your patches through the
502GMail SMTP server, see the EXAMPLE section of linkgit:git-send-email[1].
503
504For hints on submission using the IMAP interface, see the EXAMPLE
505section of linkgit:git-imap-send[1].
506
507Thunderbird
508~~~~~~~~~~~
509By default, Thunderbird will both wrap emails as well as flag
510them as being 'format=flowed', both of which will make the
Junio C Hamano076ffcc2013-02-06 05:13:21511resulting email unusable by Git.
Junio C Hamanob77f8192011-05-05 01:30:38512
513There are three different approaches: use an add-on to turn off line wraps,
514configure Thunderbird to not mangle patches, or use
515an external editor to keep Thunderbird from mangling the patches.
516
517Approach #1 (add-on)
518^^^^^^^^^^^^^^^^^^^^
519
520Install the Toggle Word Wrap add-on that is available from
521https://addons.mozilla.org/thunderbird/addon/toggle-word-wrap/
522It adds a menu entry "Enable Word Wrap" in the composer's "Options" menu
523that you can tick off. Now you can compose the message as you otherwise do
524(cut + paste, 'git format-patch' | 'git imap-send', etc), but you have to
525insert line breaks manually in any text that you type.
526
527Approach #2 (configuration)
528^^^^^^^^^^^^^^^^^^^^^^^^^^^
529Three steps:
530
5311. Configure your mail server composition as plain text:
532 Edit...Account Settings...Composition & Addressing,
533 uncheck "Compose Messages in HTML".
534
5352. Configure your general composition window to not wrap.
536+
537In Thunderbird 2:
538Edit..Preferences..Composition, wrap plain text messages at 0
539+
540In Thunderbird 3:
541Edit..Preferences..Advanced..Config Editor. Search for
542"mail.wrap_long_lines".
Junio C Hamano369e3402013-10-15 18:40:25543Toggle it to make sure it is set to `false`. Also, search for
544"mailnews.wraplength" and set the value to 0.
Junio C Hamanob77f8192011-05-05 01:30:38545
5463. Disable the use of format=flowed:
Junio C Hamano2567b322019-02-05 23:33:56547 Edit..Preferences..Advanced..Config Editor. Search for
548 "mailnews.send_plaintext_flowed".
549 Toggle it to make sure it is set to `false`.
Junio C Hamanob77f8192011-05-05 01:30:38550
551After that is done, you should be able to compose email as you
552otherwise would (cut + paste, 'git format-patch' | 'git imap-send', etc),
553and the patches will not be mangled.
554
555Approach #3 (external editor)
556^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
557
558The following Thunderbird extensions are needed:
559AboutConfig from http://aboutconfig.mozdev.org/ and
560External Editor from http://globs.org/articles.php?lng=en&pg=8
561
5621. Prepare the patch as a text file using your method of choice.
563
5642. Before opening a compose window, use Edit->Account Settings to
565 uncheck the "Compose messages in HTML format" setting in the
566 "Composition & Addressing" panel of the account to be used to
567 send the patch.
568
5693. In the main Thunderbird window, 'before' you open the compose
570 window for the patch, use Tools->about:config to set the
571 following to the indicated values:
572+
573----------
574mailnews.send_plaintext_flowed => false
575mailnews.wraplength => 0
576----------
577
5784. Open a compose window and click the external editor icon.
579
5805. In the external editor window, read in the patch file and exit
581 the editor normally.
582
583Side note: it may be possible to do step 2 with
584about:config and the following settings but no one's tried yet.
585
586----------
587mail.html_compose => false
588mail.identity.default.compose_html => false
589mail.identity.id?.compose_html => false
590----------
591
592There is a script in contrib/thunderbird-patch-inline which can help
593you include patches with Thunderbird in an easy way. To use it, do the
594steps above and then use the script as the external editor.
595
596KMail
597~~~~~
598This should help you to submit patches inline using KMail.
599
6001. Prepare the patch as a text file.
601
6022. Click on New Mail.
603
6043. Go under "Options" in the Composer window and be sure that
605 "Word wrap" is not set.
606
6074. Use Message -> Insert file... and insert the patch.
608
6095. Back in the compose window: add whatever other text you wish to the
610 message, complete the addressing and subject fields, and press send.
611
Junio C Hamanof2a3a752016-05-23 22:54:39612BASE TREE INFORMATION
613---------------------
614
615The base tree information block is used for maintainers or third party
616testers to know the exact state the patch series applies to. It consists
617of the 'base commit', which is a well-known commit that is part of the
618stable part of the project history everybody else works off of, and zero
619or more 'prerequisite patches', which are well-known patches in flight
620that is not yet part of the 'base commit' that need to be applied on top
621of 'base commit' in topological order before the patches can be applied.
622
623The 'base commit' is shown as "base-commit: " followed by the 40-hex of
624the commit object name. A 'prerequisite patch' is shown as
625"prerequisite-patch-id: " followed by the 40-hex 'patch id', which can
626be obtained by passing the patch through the `git patch-id --stable`
627command.
628
629Imagine that on top of the public commit P, you applied well-known
630patches X, Y and Z from somebody else, and then built your three-patch
631series A, B, C, the history would be like:
632
633................................................
634---P---X---Y---Z---A---B---C
635................................................
636
637With `git format-patch --base=P -3 C` (or variants thereof, e.g. with
Junio C Hamanoe25cc812017-04-24 06:17:43638`--cover-letter` or using `Z..C` instead of `-3 C` to specify the
Junio C Hamanof2a3a752016-05-23 22:54:39639range), the base tree information block is shown at the end of the
640first message the command outputs (either the first patch, or the
641cover letter), like this:
642
643------------
644base-commit: P
645prerequisite-patch-id: X
646prerequisite-patch-id: Y
647prerequisite-patch-id: Z
648------------
649
650For non-linear topology, such as
651
652................................................
653---P---X---A---M---C
654 \ /
655 Y---Z---B
656................................................
657
658You can also use `git format-patch --base=P -3 C` to generate patches
659for A, B and C, and the identifiers for P, X, Y, Z are appended at the
660end of the first message.
661
662If set `--base=auto` in cmdline, it will track base commit automatically,
663the base commit will be the merge base of tip commit of the remote-tracking
664branch and revision-range specified in cmdline.
665For a local branch, you need to track a remote branch by `git branch
666--set-upstream-to` before using this option.
Junio C Hamanob77f8192011-05-05 01:30:38667
Junio C Hamano1a4e8412005-12-27 08:17:23668EXAMPLES
669--------
670
Junio C Hamano6d76d612008-05-09 05:46:08671* Extract commits between revisions R1 and R2, and apply them on top of
Junio C Hamano2567b322019-02-05 23:33:56672 the current branch using 'git am' to cherry-pick them:
Junio C Hamano6d76d612008-05-09 05:46:08673+
674------------
Junio C Hamanoba4b9282008-07-06 05:20:31675$ git format-patch -k --stdout R1..R2 | git am -3 -k
Junio C Hamano6d76d612008-05-09 05:46:08676------------
Junio C Hamano1a4e8412005-12-27 08:17:23677
Junio C Hamano6d76d612008-05-09 05:46:08678* Extract all commits which are in the current branch but not in the
Junio C Hamano2567b322019-02-05 23:33:56679 origin branch:
Junio C Hamano6d76d612008-05-09 05:46:08680+
681------------
682$ git format-patch origin
683------------
684+
685For each commit a separate file is created in the current directory.
Junio C Hamano1a4e8412005-12-27 08:17:23686
Junio C Hamano6d76d612008-05-09 05:46:08687* Extract all commits that lead to 'origin' since the inception of the
Junio C Hamano2567b322019-02-05 23:33:56688 project:
Junio C Hamano6d76d612008-05-09 05:46:08689+
690------------
Junio C Hamanoba4b9282008-07-06 05:20:31691$ git format-patch --root origin
Junio C Hamano6d76d612008-05-09 05:46:08692------------
Junio C Hamano7d9e9bd2007-08-29 07:31:47693
Junio C Hamano6d76d612008-05-09 05:46:08694* The same as the previous one:
695+
696------------
697$ git format-patch -M -B origin
698------------
699+
700Additionally, it detects and handles renames and complete rewrites
701intelligently to produce a renaming patch. A renaming patch reduces
Junio C Hamanof4581102009-04-25 08:29:59702the amount of text output, and generally makes it easier to review.
Junio C Hamano076ffcc2013-02-06 05:13:21703Note that non-Git "patch" programs won't understand renaming patches, so
704use it only when you know the recipient uses Git to apply your patch.
Junio C Hamano1a4e8412005-12-27 08:17:23705
Junio C Hamano6d76d612008-05-09 05:46:08706* Extract three topmost commits from the current branch and format them
Junio C Hamano2567b322019-02-05 23:33:56707 as e-mailable patches:
Junio C Hamano6d76d612008-05-09 05:46:08708+
709------------
710$ git format-patch -3
711------------
Junio C Hamano1a4e8412005-12-27 08:17:23712
Junio C Hamano9049d912008-05-29 02:09:50713SEE ALSO
Junio C Hamano1a4e8412005-12-27 08:17:23714--------
Junio C Hamano35738e82008-01-07 07:55:46715linkgit:git-am[1], linkgit:git-send-email[1]
Junio C Hamano1a4e8412005-12-27 08:17:23716
Junio C Hamano1a4e8412005-12-27 08:17:23717GIT
718---
Junio C Hamanof7c042d2008-06-06 22:50:53719Part of the linkgit:git[1] suite