1GIT-FORMAT-PATCH(1)               Git Manual               GIT-FORMAT-PATCH(1)
2
3
4

NAME

6       git-format-patch - Prepare patches for e-mail submission
7

SYNOPSIS

9       git format-patch [-k] [(-o|--output-directory) <dir> | --stdout]
10                          [--no-thread | --thread[=<style>]]
11                          [(--attach|--inline)[=<boundary>] | --no-attach]
12                          [-s | --signoff]
13                          [--signature=<signature> | --no-signature]
14                          [--signature-file=<file>]
15                          [-n | --numbered | -N | --no-numbered]
16                          [--start-number <n>] [--numbered-files]
17                          [--in-reply-to=<message id>] [--suffix=.<sfx>]
18                          [--ignore-if-in-upstream] [--always]
19                          [--cover-from-description=<mode>]
20                          [--rfc] [--subject-prefix=<subject prefix>]
21                          [(--reroll-count|-v) <n>]
22                          [--to=<email>] [--cc=<email>]
23                          [--[no-]cover-letter] [--quiet]
24                          [--[no-]encode-email-headers]
25                          [--no-notes | --notes[=<ref>]]
26                          [--interdiff=<previous>]
27                          [--range-diff=<previous> [--creation-factor=<percent>]]
28                          [--filename-max-length=<n>]
29                          [--progress]
30                          [<common diff options>]
31                          [ <since> | <revision range> ]
32

DESCRIPTION

34       Prepare each non-merge commit with its "patch" in one "message" per
35       commit, formatted to resemble a UNIX mailbox. The output of this
36       command is convenient for e-mail submission or for use with git am.
37
38       A "message" generated by the command consists of three parts:
39
40       •   A brief metadata header that begins with From <commit> with a fixed
41           Mon Sep 17 00:00:00 2001 datestamp to help programs like "file(1)"
42           to recognize that the file is an output from this command, fields
43           that record the author identity, the author date, and the title of
44           the change (taken from the first paragraph of the commit log
45           message).
46
47       •   The second and subsequent paragraphs of the commit log message.
48
49       •   The "patch", which is the "diff -p --stat" output (see git-diff(1))
50           between the commit and its parent.
51
52       The log message and the patch are separated by a line with a three-dash
53       line.
54
55       There are two ways to specify which commits to operate on.
56
57        1. A single commit, <since>, specifies that the commits leading to the
58           tip of the current branch that are not in the history that leads to
59           the <since> to be output.
60
61        2. Generic <revision range> expression (see "SPECIFYING REVISIONS"
62           section in gitrevisions(7)) means the commits in the specified
63           range.
64
65       The first rule takes precedence in the case of a single <commit>. To
66       apply the second rule, i.e., format everything since the beginning of
67       history up until <commit>, use the --root option: git format-patch
68       --root <commit>. If you want to format only <commit> itself, you can do
69       this with git format-patch -1 <commit>.
70
71       By default, each output file is numbered sequentially from 1, and uses
72       the first line of the commit message (massaged for pathname safety) as
73       the filename. With the --numbered-files option, the output file names
74       will only be numbers, without the first line of the commit appended.
75       The names of the output files are printed to standard output, unless
76       the --stdout option is specified.
77
78       If -o is specified, output files are created in <dir>. Otherwise they
79       are created in the current working directory. The default path can be
80       set with the format.outputDirectory configuration option. The -o option
81       takes precedence over format.outputDirectory. To store patches in the
82       current working directory even when format.outputDirectory points
83       elsewhere, use -o .. All directory components will be created.
84
85       By default, the subject of a single patch is "[PATCH] " followed by the
86       concatenation of lines from the commit message up to the first blank
87       line (see the DISCUSSION section of git-commit(1)).
88
89       When multiple patches are output, the subject prefix will instead be
90       "[PATCH n/m] ". To force 1/1 to be added for a single patch, use -n. To
91       omit patch numbers from the subject, use -N.
92
93       If given --thread, git-format-patch will generate In-Reply-To and
94       References headers to make the second and subsequent patch mails appear
95       as replies to the first mail; this also generates a Message-ID header
96       to reference.
97

OPTIONS

99       -p, --no-stat
100           Generate plain patches without any diffstats.
101
102       -U<n>, --unified=<n>
103           Generate diffs with <n> lines of context instead of the usual
104           three.
105
106       --output=<file>
107           Output to a specific file instead of stdout.
108
109       --output-indicator-new=<char>, --output-indicator-old=<char>,
110       --output-indicator-context=<char>
111           Specify the character used to indicate new, old or context lines in
112           the generated patch. Normally they are +, - and ' ' respectively.
113
114       --indent-heuristic
115           Enable the heuristic that shifts diff hunk boundaries to make
116           patches easier to read. This is the default.
117
118       --no-indent-heuristic
119           Disable the indent heuristic.
120
121       --minimal
122           Spend extra time to make sure the smallest possible diff is
123           produced.
124
125       --patience
126           Generate a diff using the "patience diff" algorithm.
127
128       --histogram
129           Generate a diff using the "histogram diff" algorithm.
130
131       --anchored=<text>
132           Generate a diff using the "anchored diff" algorithm.
133
134           This option may be specified more than once.
135
136           If a line exists in both the source and destination, exists only
137           once, and starts with this text, this algorithm attempts to prevent
138           it from appearing as a deletion or addition in the output. It uses
139           the "patience diff" algorithm internally.
140
141       --diff-algorithm={patience|minimal|histogram|myers}
142           Choose a diff algorithm. The variants are as follows:
143
144           default, myers
145               The basic greedy diff algorithm. Currently, this is the
146               default.
147
148           minimal
149               Spend extra time to make sure the smallest possible diff is
150               produced.
151
152           patience
153               Use "patience diff" algorithm when generating patches.
154
155           histogram
156               This algorithm extends the patience algorithm to "support
157               low-occurrence common elements".
158
159           For instance, if you configured the diff.algorithm variable to a
160           non-default value and want to use the default one, then you have to
161           use --diff-algorithm=default option.
162
163       --stat[=<width>[,<name-width>[,<count>]]]
164           Generate a diffstat. By default, as much space as necessary will be
165           used for the filename part, and the rest for the graph part.
166           Maximum width defaults to terminal width, or 80 columns if not
167           connected to a terminal, and can be overridden by <width>. The
168           width of the filename part can be limited by giving another width
169           <name-width> after a comma or by setting
170           diff.statNameWidth=<width>. The width of the graph part can be
171           limited by using --stat-graph-width=<width> or by setting
172           diff.statGraphWidth=<width>. Using --stat or --stat-graph-width
173           affects all commands generating a stat graph, while setting
174           diff.statNameWidth or diff.statGraphWidth does not affect git
175           format-patch. By giving a third parameter <count>, you can limit
176           the output to the first <count> lines, followed by ...  if there
177           are more.
178
179           These parameters can also be set individually with
180           --stat-width=<width>, --stat-name-width=<name-width> and
181           --stat-count=<count>.
182
183       --compact-summary
184           Output a condensed summary of extended header information such as
185           file creations or deletions ("new" or "gone", optionally "+l" if
186           it’s a symlink) and mode changes ("+x" or "-x" for adding or
187           removing executable bit respectively) in diffstat. The information
188           is put between the filename part and the graph part. Implies
189           --stat.
190
191       --numstat
192           Similar to --stat, but shows number of added and deleted lines in
193           decimal notation and pathname without abbreviation, to make it more
194           machine friendly. For binary files, outputs two - instead of saying
195           0 0.
196
197       --shortstat
198           Output only the last line of the --stat format containing total
199           number of modified files, as well as number of added and deleted
200           lines.
201
202       -X[<param1,param2,...>], --dirstat[=<param1,param2,...>]
203           Output the distribution of relative amount of changes for each
204           sub-directory. The behavior of --dirstat can be customized by
205           passing it a comma separated list of parameters. The defaults are
206           controlled by the diff.dirstat configuration variable (see git-
207           config(1)). The following parameters are available:
208
209           changes
210               Compute the dirstat numbers by counting the lines that have
211               been removed from the source, or added to the destination. This
212               ignores the amount of pure code movements within a file. In
213               other words, rearranging lines in a file is not counted as much
214               as other changes. This is the default behavior when no
215               parameter is given.
216
217           lines
218               Compute the dirstat numbers by doing the regular line-based
219               diff analysis, and summing the removed/added line counts. (For
220               binary files, count 64-byte chunks instead, since binary files
221               have no natural concept of lines). This is a more expensive
222               --dirstat behavior than the changes behavior, but it does count
223               rearranged lines within a file as much as other changes. The
224               resulting output is consistent with what you get from the other
225               --*stat options.
226
227           files
228               Compute the dirstat numbers by counting the number of files
229               changed. Each changed file counts equally in the dirstat
230               analysis. This is the computationally cheapest --dirstat
231               behavior, since it does not have to look at the file contents
232               at all.
233
234           cumulative
235               Count changes in a child directory for the parent directory as
236               well. Note that when using cumulative, the sum of the
237               percentages reported may exceed 100%. The default
238               (non-cumulative) behavior can be specified with the
239               noncumulative parameter.
240
241           <limit>
242               An integer parameter specifies a cut-off percent (3% by
243               default). Directories contributing less than this percentage of
244               the changes are not shown in the output.
245
246           Example: The following will count changed files, while ignoring
247           directories with less than 10% of the total amount of changed
248           files, and accumulating child directory counts in the parent
249           directories: --dirstat=files,10,cumulative.
250
251       --cumulative
252           Synonym for --dirstat=cumulative
253
254       --dirstat-by-file[=<param1,param2>...]
255           Synonym for --dirstat=files,param1,param2...
256
257       --summary
258           Output a condensed summary of extended header information such as
259           creations, renames and mode changes.
260
261       --no-renames
262           Turn off rename detection, even when the configuration file gives
263           the default to do so.
264
265       --[no-]rename-empty
266           Whether to use empty blobs as rename source.
267
268       --full-index
269           Instead of the first handful of characters, show the full pre- and
270           post-image blob object names on the "index" line when generating
271           patch format output.
272
273       --binary
274           In addition to --full-index, output a binary diff that can be
275           applied with git-apply.
276
277       --abbrev[=<n>]
278           Instead of showing the full 40-byte hexadecimal object name in
279           diff-raw format output and diff-tree header lines, show the
280           shortest prefix that is at least <n> hexdigits long that uniquely
281           refers the object. In diff-patch output format, --full-index takes
282           higher precedence, i.e. if --full-index is specified, full blob
283           names will be shown regardless of --abbrev. Non default number of
284           digits can be specified with --abbrev=<n>.
285
286       -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]
287           Break complete rewrite changes into pairs of delete and create.
288           This serves two purposes:
289
290           It affects the way a change that amounts to a total rewrite of a
291           file not as a series of deletion and insertion mixed together with
292           a very few lines that happen to match textually as the context, but
293           as a single deletion of everything old followed by a single
294           insertion of everything new, and the number m controls this aspect
295           of the -B option (defaults to 60%).  -B/70% specifies that less
296           than 30% of the original should remain in the result for Git to
297           consider it a total rewrite (i.e. otherwise the resulting patch
298           will be a series of deletion and insertion mixed together with
299           context lines).
300
301           When used with -M, a totally-rewritten file is also considered as
302           the source of a rename (usually -M only considers a file that
303           disappeared as the source of a rename), and the number n controls
304           this aspect of the -B option (defaults to 50%).  -B20% specifies
305           that a change with addition and deletion compared to 20% or more of
306           the file’s size are eligible for being picked up as a possible
307           source of a rename to another file.
308
309       -M[<n>], --find-renames[=<n>]
310           Detect renames. If n is specified, it is a threshold on the
311           similarity index (i.e. amount of addition/deletions compared to the
312           file’s size). For example, -M90% means Git should consider a
313           delete/add pair to be a rename if more than 90% of the file hasn’t
314           changed. Without a % sign, the number is to be read as a fraction,
315           with a decimal point before it. I.e., -M5 becomes 0.5, and is thus
316           the same as -M50%. Similarly, -M05 is the same as -M5%. To limit
317           detection to exact renames, use -M100%. The default similarity
318           index is 50%.
319
320       -C[<n>], --find-copies[=<n>]
321           Detect copies as well as renames. See also --find-copies-harder. If
322           n is specified, it has the same meaning as for -M<n>.
323
324       --find-copies-harder
325           For performance reasons, by default, -C option finds copies only if
326           the original file of the copy was modified in the same changeset.
327           This flag makes the command inspect unmodified files as candidates
328           for the source of copy. This is a very expensive operation for
329           large projects, so use it with caution. Giving more than one -C
330           option has the same effect.
331
332       -D, --irreversible-delete
333           Omit the preimage for deletes, i.e. print only the header but not
334           the diff between the preimage and /dev/null. The resulting patch is
335           not meant to be applied with patch or git apply; this is solely for
336           people who want to just concentrate on reviewing the text after the
337           change. In addition, the output obviously lacks enough information
338           to apply such a patch in reverse, even manually, hence the name of
339           the option.
340
341           When used together with -B, omit also the preimage in the deletion
342           part of a delete/create pair.
343
344       -l<num>
345           The -M and -C options involve some preliminary steps that can
346           detect subsets of renames/copies cheaply, followed by an exhaustive
347           fallback portion that compares all remaining unpaired destinations
348           to all relevant sources. (For renames, only remaining unpaired
349           sources are relevant; for copies, all original sources are
350           relevant.) For N sources and destinations, this exhaustive check is
351           O(N^2). This option prevents the exhaustive portion of rename/copy
352           detection from running if the number of source/destination files
353           involved exceeds the specified number. Defaults to
354           diff.renameLimit. Note that a value of 0 is treated as unlimited.
355
356       -O<orderfile>
357           Control the order in which files appear in the output. This
358           overrides the diff.orderFile configuration variable (see git-
359           config(1)). To cancel diff.orderFile, use -O/dev/null.
360
361           The output order is determined by the order of glob patterns in
362           <orderfile>. All files with pathnames that match the first pattern
363           are output first, all files with pathnames that match the second
364           pattern (but not the first) are output next, and so on. All files
365           with pathnames that do not match any pattern are output last, as if
366           there was an implicit match-all pattern at the end of the file. If
367           multiple pathnames have the same rank (they match the same pattern
368           but no earlier patterns), their output order relative to each other
369           is the normal order.
370
371           <orderfile> is parsed as follows:
372
373           •   Blank lines are ignored, so they can be used as separators for
374               readability.
375
376           •   Lines starting with a hash ("#") are ignored, so they can be
377               used for comments. Add a backslash ("\") to the beginning of
378               the pattern if it starts with a hash.
379
380           •   Each other line contains a single pattern.
381
382           Patterns have the same syntax and semantics as patterns used for
383           fnmatch(3) without the FNM_PATHNAME flag, except a pathname also
384           matches a pattern if removing any number of the final pathname
385           components matches the pattern. For example, the pattern "foo*bar"
386           matches "fooasdfbar" and "foo/bar/baz/asdf" but not "foobarx".
387
388       --skip-to=<file>, --rotate-to=<file>
389           Discard the files before the named <file> from the output (i.e.
390           skip to), or move them to the end of the output (i.e.  rotate to).
391           These options were invented primarily for the use of the git
392           difftool command, and may not be very useful otherwise.
393
394       --relative[=<path>], --no-relative
395           When run from a subdirectory of the project, it can be told to
396           exclude changes outside the directory and show pathnames relative
397           to it with this option. When you are not in a subdirectory (e.g. in
398           a bare repository), you can name which subdirectory to make the
399           output relative to by giving a <path> as an argument.
400           --no-relative can be used to countermand both diff.relative config
401           option and previous --relative.
402
403       -a, --text
404           Treat all files as text.
405
406       --ignore-cr-at-eol
407           Ignore carriage-return at the end of line when doing a comparison.
408
409       --ignore-space-at-eol
410           Ignore changes in whitespace at EOL.
411
412       -b, --ignore-space-change
413           Ignore changes in amount of whitespace. This ignores whitespace at
414           line end, and considers all other sequences of one or more
415           whitespace characters to be equivalent.
416
417       -w, --ignore-all-space
418           Ignore whitespace when comparing lines. This ignores differences
419           even if one line has whitespace where the other line has none.
420
421       --ignore-blank-lines
422           Ignore changes whose lines are all blank.
423
424       -I<regex>, --ignore-matching-lines=<regex>
425           Ignore changes whose all lines match <regex>. This option may be
426           specified more than once.
427
428       --inter-hunk-context=<lines>
429           Show the context between diff hunks, up to the specified number of
430           lines, thereby fusing hunks that are close to each other. Defaults
431           to diff.interHunkContext or 0 if the config option is unset.
432
433       -W, --function-context
434           Show whole function as context lines for each change. The function
435           names are determined in the same way as git diff works out patch
436           hunk headers (see Defining a custom hunk-header in
437           gitattributes(5)).
438
439       --ext-diff
440           Allow an external diff helper to be executed. If you set an
441           external diff driver with gitattributes(5), you need to use this
442           option with git-log(1) and friends.
443
444       --no-ext-diff
445           Disallow external diff drivers.
446
447       --textconv, --no-textconv
448           Allow (or disallow) external text conversion filters to be run when
449           comparing binary files. See gitattributes(5) for details. Because
450           textconv filters are typically a one-way conversion, the resulting
451           diff is suitable for human consumption, but cannot be applied. For
452           this reason, textconv filters are enabled by default only for git-
453           diff(1) and git-log(1), but not for git-format-patch(1) or diff
454           plumbing commands.
455
456       --ignore-submodules[=<when>]
457           Ignore changes to submodules in the diff generation. <when> can be
458           either "none", "untracked", "dirty" or "all", which is the default.
459           Using "none" will consider the submodule modified when it either
460           contains untracked or modified files or its HEAD differs from the
461           commit recorded in the superproject and can be used to override any
462           settings of the ignore option in git-config(1) or gitmodules(5).
463           When "untracked" is used submodules are not considered dirty when
464           they only contain untracked content (but they are still scanned for
465           modified content). Using "dirty" ignores all changes to the work
466           tree of submodules, only changes to the commits stored in the
467           superproject are shown (this was the behavior until 1.7.0). Using
468           "all" hides all changes to submodules.
469
470       --src-prefix=<prefix>
471           Show the given source prefix instead of "a/".
472
473       --dst-prefix=<prefix>
474           Show the given destination prefix instead of "b/".
475
476       --no-prefix
477           Do not show any source or destination prefix.
478
479       --default-prefix
480           Use the default source and destination prefixes ("a/" and "b/").
481           This is usually the default already, but may be used to override
482           config such as diff.noprefix.
483
484       --line-prefix=<prefix>
485           Prepend an additional prefix to every line of output.
486
487       --ita-invisible-in-index
488           By default entries added by "git add -N" appear as an existing
489           empty file in "git diff" and a new file in "git diff --cached".
490           This option makes the entry appear as a new file in "git diff" and
491           non-existent in "git diff --cached". This option could be reverted
492           with --ita-visible-in-index. Both options are experimental and
493           could be removed in future.
494
495       For more detailed explanation on these common options, see also
496       gitdiffcore(7).
497
498       -<n>
499           Prepare patches from the topmost <n> commits.
500
501       -o <dir>, --output-directory <dir>
502           Use <dir> to store the resulting files, instead of the current
503           working directory.
504
505       -n, --numbered
506           Name output in [PATCH n/m] format, even with a single patch.
507
508       -N, --no-numbered
509           Name output in [PATCH] format.
510
511       --start-number <n>
512           Start numbering the patches at <n> instead of 1.
513
514       --numbered-files
515           Output file names will be a simple number sequence without the
516           default first line of the commit appended.
517
518       -k, --keep-subject
519           Do not strip/add [PATCH] from the first line of the commit log
520           message.
521
522       -s, --signoff
523           Add a Signed-off-by trailer to the commit message, using the
524           committer identity of yourself. See the signoff option in git-
525           commit(1) for more information.
526
527       --stdout
528           Print all commits to the standard output in mbox format, instead of
529           creating a file for each one.
530
531       --attach[=<boundary>]
532           Create multipart/mixed attachment, the first part of which is the
533           commit message and the patch itself in the second part, with
534           Content-Disposition: attachment.
535
536       --no-attach
537           Disable the creation of an attachment, overriding the configuration
538           setting.
539
540       --inline[=<boundary>]
541           Create multipart/mixed attachment, the first part of which is the
542           commit message and the patch itself in the second part, with
543           Content-Disposition: inline.
544
545       --thread[=<style>], --no-thread
546           Controls addition of In-Reply-To and References headers to make the
547           second and subsequent mails appear as replies to the first. Also
548           controls generation of the Message-ID header to reference.
549
550           The optional <style> argument can be either shallow or deep.
551           shallow threading makes every mail a reply to the head of the
552           series, where the head is chosen from the cover letter, the
553           --in-reply-to, and the first patch mail, in this order.  deep
554           threading makes every mail a reply to the previous one.
555
556           The default is --no-thread, unless the format.thread configuration
557           is set.  --thread without an argument is equivalent to
558           --thread=shallow.
559
560           Beware that the default for git send-email is to thread emails
561           itself. If you want git format-patch to take care of threading, you
562           will want to ensure that threading is disabled for git send-email.
563
564       --in-reply-to=<message id>
565           Make the first mail (or all the mails with --no-thread) appear as a
566           reply to the given <message id>, which avoids breaking threads to
567           provide a new patch series.
568
569       --ignore-if-in-upstream
570           Do not include a patch that matches a commit in <until>..<since>.
571           This will examine all patches reachable from <since> but not from
572           <until> and compare them with the patches being generated, and any
573           patch that matches is ignored.
574
575       --always
576           Include patches for commits that do not introduce any change, which
577           are omitted by default.
578
579       --cover-from-description=<mode>
580           Controls which parts of the cover letter will be automatically
581           populated using the branch’s description.
582
583           If <mode> is message or default, the cover letter subject will be
584           populated with placeholder text. The body of the cover letter will
585           be populated with the branch’s description. This is the default
586           mode when no configuration nor command line option is specified.
587
588           If <mode> is subject, the first paragraph of the branch description
589           will populate the cover letter subject. The remainder of the
590           description will populate the body of the cover letter.
591
592           If <mode> is auto, if the first paragraph of the branch description
593           is greater than 100 bytes, then the mode will be message, otherwise
594           subject will be used.
595
596           If <mode> is none, both the cover letter subject and body will be
597           populated with placeholder text.
598
599       --description-file=<file>
600           Use the contents of <file> instead of the branch’s description for
601           generating the cover letter.
602
603       --subject-prefix=<subject prefix>
604           Instead of the standard [PATCH] prefix in the subject line, instead
605           use [<subject prefix>]. This can be used to name a patch series,
606           and can be combined with the --numbered option.
607
608           The configuration variable format.subjectPrefix may also be used to
609           configure a subject prefix to apply to a given repository for all
610           patches. This is often useful on mailing lists which receive
611           patches for several repositories and can be used to disambiguate
612           the patches (with a value of e.g. "PATCH my-project").
613
614       --filename-max-length=<n>
615           Instead of the standard 64 bytes, chomp the generated output
616           filenames at around <n> bytes (too short a value will be silently
617           raised to a reasonable length). Defaults to the value of the
618           format.filenameMaxLength configuration variable, or 64 if
619           unconfigured.
620
621       --rfc
622           Prepends "RFC" to the subject prefix (producing "RFC PATCH" by
623           default). RFC means "Request For Comments"; use this when sending
624           an experimental patch for discussion rather than application.
625
626       -v <n>, --reroll-count=<n>
627           Mark the series as the <n>-th iteration of the topic. The output
628           filenames have v<n> prepended to them, and the subject prefix
629           ("PATCH" by default, but configurable via the --subject-prefix
630           option) has ` v<n>` appended to it. E.g.  --reroll-count=4 may
631           produce v4-0001-add-makefile.patch file that has "Subject: [PATCH
632           v4 1/20] Add makefile" in it.  <n> does not have to be an integer
633           (e.g. "--reroll-count=4.4", or "--reroll-count=4rev2" are allowed),
634           but the downside of using such a reroll-count is that the
635           range-diff/interdiff with the previous version does not state
636           exactly which version the new iteration is compared against.
637
638       --to=<email>
639           Add a To: header to the email headers. This is in addition to any
640           configured headers, and may be used multiple times. The negated
641           form --no-to discards all To: headers added so far (from config or
642           command line).
643
644       --cc=<email>
645           Add a Cc: header to the email headers. This is in addition to any
646           configured headers, and may be used multiple times. The negated
647           form --no-cc discards all Cc: headers added so far (from config or
648           command line).
649
650       --from, --from=<ident>
651           Use ident in the From: header of each commit email. If the author
652           ident of the commit is not textually identical to the provided
653           ident, place a From: header in the body of the message with the
654           original author. If no ident is given, use the committer ident.
655
656           Note that this option is only useful if you are actually sending
657           the emails and want to identify yourself as the sender, but retain
658           the original author (and git am will correctly pick up the in-body
659           header). Note also that git send-email already handles this
660           transformation for you, and this option should not be used if you
661           are feeding the result to git send-email.
662
663       --[no-]force-in-body-from
664           With the e-mail sender specified via the --from option, by default,
665           an in-body "From:" to identify the real author of the commit is
666           added at the top of the commit log message if the sender is
667           different from the author. With this option, the in-body "From:" is
668           added even when the sender and the author have the same name and
669           address, which may help if the mailing list software mangles the
670           sender’s identity. Defaults to the value of the
671           format.forceInBodyFrom configuration variable.
672
673       --add-header=<header>
674           Add an arbitrary header to the email headers. This is in addition
675           to any configured headers, and may be used multiple times. For
676           example, --add-header="Organization: git-foo". The negated form
677           --no-add-header discards all (To:, Cc:, and custom) headers added
678           so far from config or command line.
679
680       --[no-]cover-letter
681           In addition to the patches, generate a cover letter file containing
682           the branch description, shortlog and the overall diffstat. You can
683           fill in a description in the file before sending it out.
684
685       --encode-email-headers, --no-encode-email-headers
686           Encode email headers that have non-ASCII characters with
687           "Q-encoding" (described in RFC 2047), instead of outputting the
688           headers verbatim. Defaults to the value of the
689           format.encodeEmailHeaders configuration variable.
690
691       --interdiff=<previous>
692           As a reviewer aid, insert an interdiff into the cover letter, or as
693           commentary of the lone patch of a 1-patch series, showing the
694           differences between the previous version of the patch series and
695           the series currently being formatted.  previous is a single
696           revision naming the tip of the previous series which shares a
697           common base with the series being formatted (for example git
698           format-patch --cover-letter --interdiff=feature/v1 -3 feature/v2).
699
700       --range-diff=<previous>
701           As a reviewer aid, insert a range-diff (see git-range-diff(1)) into
702           the cover letter, or as commentary of the lone patch of a 1-patch
703           series, showing the differences between the previous version of the
704           patch series and the series currently being formatted.  previous
705           can be a single revision naming the tip of the previous series if
706           it shares a common base with the series being formatted (for
707           example git format-patch --cover-letter --range-diff=feature/v1 -3
708           feature/v2), or a revision range if the two versions of the series
709           are disjoint (for example git format-patch --cover-letter
710           --range-diff=feature/v1~3..feature/v1 -3 feature/v2).
711
712           Note that diff options passed to the command affect how the primary
713           product of format-patch is generated, and they are not passed to
714           the underlying range-diff machinery used to generate the
715           cover-letter material (this may change in the future).
716
717       --creation-factor=<percent>
718           Used with --range-diff, tweak the heuristic which matches up
719           commits between the previous and current series of patches by
720           adjusting the creation/deletion cost fudge factor. See git-range-
721           diff(1)) for details.
722
723       --notes[=<ref>], --no-notes
724           Append the notes (see git-notes(1)) for the commit after the
725           three-dash line.
726
727           The expected use case of this is to write supporting explanation
728           for the commit that does not belong to the commit log message
729           proper, and include it with the patch submission. While one can
730           simply write these explanations after format-patch has run but
731           before sending, keeping them as Git notes allows them to be
732           maintained between versions of the patch series (but see the
733           discussion of the notes.rewrite configuration options in git-
734           notes(1) to use this workflow).
735
736           The default is --no-notes, unless the format.notes configuration is
737           set.
738
739       --[no-]signature=<signature>
740           Add a signature to each message produced. Per RFC 3676 the
741           signature is separated from the body by a line with '-- ' on it. If
742           the signature option is omitted the signature defaults to the Git
743           version number.
744
745       --signature-file=<file>
746           Works just like --signature except the signature is read from a
747           file.
748
749       --suffix=.<sfx>
750           Instead of using .patch as the suffix for generated filenames, use
751           specified suffix. A common alternative is --suffix=.txt. Leaving
752           this empty will remove the .patch suffix.
753
754           Note that the leading character does not have to be a dot; for
755           example, you can use --suffix=-patch to get
756           0001-description-of-my-change-patch.
757
758       -q, --quiet
759           Do not print the names of the generated files to standard output.
760
761       --no-binary
762           Do not output contents of changes in binary files, instead display
763           a notice that those files changed. Patches generated using this
764           option cannot be applied properly, but they are still useful for
765           code review.
766
767       --zero-commit
768           Output an all-zero hash in each patch’s From header instead of the
769           hash of the commit.
770
771       --[no-]base[=<commit>]
772           Record the base tree information to identify the state the patch
773           series applies to. See the BASE TREE INFORMATION section below for
774           details. If <commit> is "auto", a base commit is automatically
775           chosen. The --no-base option overrides a format.useAutoBase
776           configuration.
777
778       --root
779           Treat the revision argument as a <revision range>, even if it is
780           just a single commit (that would normally be treated as a <since>).
781           Note that root commits included in the specified range are always
782           formatted as creation patches, independently of this flag.
783
784       --progress
785           Show progress reports on stderr as patches are generated.
786

CONFIGURATION

788       You can specify extra mail header lines to be added to each message,
789       defaults for the subject prefix and file suffix, number patches when
790       outputting more than one patch, add "To:" or "Cc:" headers, configure
791       attachments, change the patch output directory, and sign off patches
792       with configuration variables.
793
794           [format]
795                   headers = "Organization: git-foo\n"
796                   subjectPrefix = CHANGE
797                   suffix = .txt
798                   numbered = auto
799                   to = <email>
800                   cc = <email>
801                   attach [ = mime-boundary-string ]
802                   signOff = true
803                   outputDirectory = <directory>
804                   coverLetter = auto
805                   coverFromDescription = auto
806

DISCUSSION

808       The patch produced by git format-patch is in UNIX mailbox format, with
809       a fixed "magic" time stamp to indicate that the file is output from
810       format-patch rather than a real mailbox, like so:
811
812           From 8f72bad1baf19a53459661343e21d6491c3908d3 Mon Sep 17 00:00:00 2001
813           From: Tony Luck <tony.luck@intel.com>
814           Date: Tue, 13 Jul 2010 11:42:54 -0700
815           Subject: [PATCH] =?UTF-8?q?[IA64]=20Put=20ia64=20config=20files=20on=20the=20?=
816            =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20diet?=
817           MIME-Version: 1.0
818           Content-Type: text/plain; charset=UTF-8
819           Content-Transfer-Encoding: 8bit
820
821           arch/arm config files were slimmed down using a python script
822           (See commit c2330e286f68f1c408b4aa6515ba49d57f05beae comment)
823
824           Do the same for ia64 so we can have sleek & trim looking
825           ...
826
827       Typically it will be placed in a MUA’s drafts folder, edited to add
828       timely commentary that should not go in the changelog after the three
829       dashes, and then sent as a message whose body, in our example, starts
830       with "arch/arm config files were...". On the receiving end, readers can
831       save interesting patches in a UNIX mailbox and apply them with git-
832       am(1).
833
834       When a patch is part of an ongoing discussion, the patch generated by
835       git format-patch can be tweaked to take advantage of the git am
836       --scissors feature. After your response to the discussion comes a line
837       that consists solely of "-- >8 --" (scissors and perforation), followed
838       by the patch with unnecessary header fields removed:
839
840           ...
841           > So we should do such-and-such.
842
843           Makes sense to me.  How about this patch?
844
845           -- >8 --
846           Subject: [IA64] Put ia64 config files on the Uwe Kleine-König diet
847
848           arch/arm config files were slimmed down using a python script
849           ...
850
851       When sending a patch this way, most often you are sending your own
852       patch, so in addition to the "From $SHA1 $magic_timestamp" marker you
853       should omit From: and Date: lines from the patch file. The patch title
854       is likely to be different from the subject of the discussion the patch
855       is in response to, so it is likely that you would want to keep the
856       Subject: line, like the example above.
857
858   Checking for patch corruption
859       Many mailers if not set up properly will corrupt whitespace. Here are
860       two common types of corruption:
861
862       •   Empty context lines that do not have any whitespace.
863
864       •   Non-empty context lines that have one extra whitespace at the
865           beginning.
866
867       One way to test if your MUA is set up correctly is:
868
869       •   Send the patch to yourself, exactly the way you would, except with
870           To: and Cc: lines that do not contain the list and maintainer
871           address.
872
873       •   Save that patch to a file in UNIX mailbox format. Call it a.patch,
874           say.
875
876       •   Apply it:
877
878               $ git fetch <project> master:test-apply
879               $ git switch test-apply
880               $ git restore --source=HEAD --staged --worktree :/
881               $ git am a.patch
882
883       If it does not apply correctly, there can be various reasons.
884
885       •   The patch itself does not apply cleanly. That is bad but does not
886           have much to do with your MUA. You might want to rebase the patch
887           with git-rebase(1) before regenerating it in this case.
888
889       •   The MUA corrupted your patch; "am" would complain that the patch
890           does not apply. Look in the .git/rebase-apply/ subdirectory and see
891           what patch file contains and check for the common corruption
892           patterns mentioned above.
893
894       •   While at it, check the info and final-commit files as well. If what
895           is in final-commit is not exactly what you would want to see in the
896           commit log message, it is very likely that the receiver would end
897           up hand editing the log message when applying your patch. Things
898           like "Hi, this is my first patch.\n" in the patch e-mail should
899           come after the three-dash line that signals the end of the commit
900           message.
901

MUA-SPECIFIC HINTS

903       Here are some hints on how to successfully submit patches inline using
904       various mailers.
905
906   GMail
907       GMail does not have any way to turn off line wrapping in the web
908       interface, so it will mangle any emails that you send. You can however
909       use "git send-email" and send your patches through the GMail SMTP
910       server, or use any IMAP email client to connect to the google IMAP
911       server and forward the emails through that.
912
913       For hints on using git send-email to send your patches through the
914       GMail SMTP server, see the EXAMPLE section of git-send-email(1).
915
916       For hints on submission using the IMAP interface, see the EXAMPLE
917       section of git-imap-send(1).
918
919   Thunderbird
920       By default, Thunderbird will both wrap emails as well as flag them as
921       being format=flowed, both of which will make the resulting email
922       unusable by Git.
923
924       There are three different approaches: use an add-on to turn off line
925       wraps, configure Thunderbird to not mangle patches, or use an external
926       editor to keep Thunderbird from mangling the patches.
927
928       Approach #1 (add-on)
929           Install the Toggle Word Wrap add-on that is available from
930           https://addons.mozilla.org/thunderbird/addon/toggle-word-wrap/ It
931           adds a menu entry "Enable Word Wrap" in the composer’s "Options"
932           menu that you can tick off. Now you can compose the message as you
933           otherwise do (cut + paste, git format-patch | git imap-send, etc),
934           but you have to insert line breaks manually in any text that you
935           type.
936
937       Approach #2 (configuration)
938           Three steps:
939
940            1. Configure your mail server composition as plain text: Edit...
941               Account Settings...Composition & Addressing, uncheck "Compose
942               Messages in HTML".
943
944            2. Configure your general composition window to not wrap.
945
946               In Thunderbird 2: Edit..Preferences..Composition, wrap plain
947               text messages at 0
948
949               In Thunderbird 3: Edit..Preferences..Advanced..Config Editor.
950               Search for "mail.wrap_long_lines". Toggle it to make sure it is
951               set to false. Also, search for "mailnews.wraplength" and set
952               the value to 0.
953
954            3. Disable the use of format=flowed:
955               Edit..Preferences..Advanced..Config Editor. Search for
956               "mailnews.send_plaintext_flowed". Toggle it to make sure it is
957               set to false.
958
959           After that is done, you should be able to compose email as you
960           otherwise would (cut + paste, git format-patch | git imap-send,
961           etc), and the patches will not be mangled.
962
963       Approach #3 (external editor)
964           The following Thunderbird extensions are needed: AboutConfig from
965           http://aboutconfig.mozdev.org/ and External Editor from
966           http://globs.org/articles.php?lng=en&pg=8
967
968            1. Prepare the patch as a text file using your method of choice.
969
970            2. Before opening a compose window, use Edit→Account Settings to
971               uncheck the "Compose messages in HTML format" setting in the
972               "Composition & Addressing" panel of the account to be used to
973               send the patch.
974
975            3. In the main Thunderbird window, before you open the compose
976               window for the patch, use Tools→about:config to set the
977               following to the indicated values:
978
979                           mailnews.send_plaintext_flowed  => false
980                           mailnews.wraplength             => 0
981
982            4. Open a compose window and click the external editor icon.
983
984            5. In the external editor window, read in the patch file and exit
985               the editor normally.
986
987           Side note: it may be possible to do step 2 with about:config and
988           the following settings but no one’s tried yet.
989
990                       mail.html_compose                       => false
991                       mail.identity.default.compose_html      => false
992                       mail.identity.id?.compose_html          => false
993
994           There is a script in contrib/thunderbird-patch-inline which can
995           help you include patches with Thunderbird in an easy way. To use
996           it, do the steps above and then use the script as the external
997           editor.
998
999   KMail
1000       This should help you to submit patches inline using KMail.
1001
1002        1. Prepare the patch as a text file.
1003
1004        2. Click on New Mail.
1005
1006        3. Go under "Options" in the Composer window and be sure that "Word
1007           wrap" is not set.
1008
1009        4. Use Message → Insert file... and insert the patch.
1010
1011        5. Back in the compose window: add whatever other text you wish to the
1012           message, complete the addressing and subject fields, and press
1013           send.
1014

BASE TREE INFORMATION

1016       The base tree information block is used for maintainers or third party
1017       testers to know the exact state the patch series applies to. It
1018       consists of the base commit, which is a well-known commit that is part
1019       of the stable part of the project history everybody else works off of,
1020       and zero or more prerequisite patches, which are well-known patches in
1021       flight that is not yet part of the base commit that need to be applied
1022       on top of base commit in topological order before the patches can be
1023       applied.
1024
1025       The base commit is shown as "base-commit: " followed by the 40-hex of
1026       the commit object name. A prerequisite patch is shown as
1027       "prerequisite-patch-id: " followed by the 40-hex patch id, which can be
1028       obtained by passing the patch through the git patch-id --stable
1029       command.
1030
1031       Imagine that on top of the public commit P, you applied well-known
1032       patches X, Y and Z from somebody else, and then built your three-patch
1033       series A, B, C, the history would be like:
1034
1035           ---P---X---Y---Z---A---B---C
1036
1037       With git format-patch --base=P -3 C (or variants thereof, e.g. with
1038       --cover-letter or using Z..C instead of -3 C to specify the range), the
1039       base tree information block is shown at the end of the first message
1040       the command outputs (either the first patch, or the cover letter), like
1041       this:
1042
1043           base-commit: P
1044           prerequisite-patch-id: X
1045           prerequisite-patch-id: Y
1046           prerequisite-patch-id: Z
1047
1048       For non-linear topology, such as
1049
1050           ---P---X---A---M---C
1051               \         /
1052                Y---Z---B
1053
1054       You can also use git format-patch --base=P -3 C to generate patches for
1055       A, B and C, and the identifiers for P, X, Y, Z are appended at the end
1056       of the first message.
1057
1058       If set --base=auto in cmdline, it will automatically compute the base
1059       commit as the merge base of tip commit of the remote-tracking branch
1060       and revision-range specified in cmdline. For a local branch, you need
1061       to make it to track a remote branch by git branch --set-upstream-to
1062       before using this option.
1063

EXAMPLES

1065       •   Extract commits between revisions R1 and R2, and apply them on top
1066           of the current branch using git am to cherry-pick them:
1067
1068               $ git format-patch -k --stdout R1..R2 | git am -3 -k
1069
1070       •   Extract all commits which are in the current branch but not in the
1071           origin branch:
1072
1073               $ git format-patch origin
1074
1075           For each commit a separate file is created in the current
1076           directory.
1077
1078       •   Extract all commits that lead to origin since the inception of the
1079           project:
1080
1081               $ git format-patch --root origin
1082
1083       •   The same as the previous one:
1084
1085               $ git format-patch -M -B origin
1086
1087           Additionally, it detects and handles renames and complete rewrites
1088           intelligently to produce a renaming patch. A renaming patch reduces
1089           the amount of text output, and generally makes it easier to review.
1090           Note that non-Git "patch" programs won’t understand renaming
1091           patches, so use it only when you know the recipient uses Git to
1092           apply your patch.
1093
1094       •   Extract three topmost commits from the current branch and format
1095           them as e-mailable patches:
1096
1097               $ git format-patch -3
1098

CAVEATS

1100       Note that format-patch will omit merge commits from the output, even if
1101       they are part of the requested range. A simple "patch" does not include
1102       enough information for the receiving end to reproduce the same merge
1103       commit.
1104

SEE ALSO

1106       git-am(1), git-send-email(1)
1107

GIT

1109       Part of the git(1) suite
1110
1111
1112
1113Git 2.43.0                        11/20/2023               GIT-FORMAT-PATCH(1)
Impressum