Home·Terminal commands

git format-patch

git

Usage

git format-patch [-<n>|<since>] [-o <dir>]

Writes one mail-shaped .patch file per commit for review by email; format-patch main means the commits after main, not main itself.

Common flags

FlagMeaning
-<n>the last n commits, e.g. -3
<since>commits after that one, e.g. origin/main
-o <dir>write the files into a directory
--stdoutone mbox stream on standard output
--cover-letteradd a 0000 summary mail
-v <n>mark the series as v<n> of a re-roll
-sadd Signed-off-by

Examples

git format-patch -3

writes 0001- to 0003- patch files for the last three commits

git format-patch origin/main --cover-letter -o outbox/

a mailable series of everything not yet upstream

git format-patch -1 --stdout > fix.patch

one commit as a single patch file

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git format-patch do?

Writes one mail-shaped .patch file per commit for review by email; format-patch main means the commits after main, not main itself.

Q. How do I type it?

git format-patch [-<n>|<since>] [-o <dir>] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-format-patch