LinuxCommandLibrary

git-format-patch

Prepare patches for email submission

TLDR

Create patches for last N commits

$ git format-patch -[n]
copy
Create patch since commit
$ git format-patch [commit]
copy
Create patch for range
$ git format-patch [commit1]..[commit2]
copy
Output to directory
$ git format-patch -o [patches/] [commit]
copy
Create single combined patch
$ git format-patch --stdout [commit] > [combined.patch]
copy
Include cover letter
$ git format-patch --cover-letter [commit]
copy

SYNOPSIS

git format-patch [options] [since] | [revision-range]

DESCRIPTION

git format-patch generates patch files from commits in a format suitable for email-based code review and submission workflows. Each commit is formatted as a separate .patch file containing the diff, commit metadata, and message in mbox format.
This command is fundamental to email-based development workflows used by projects like the Linux kernel and Git itself. The generated patches can be sent using git send-email or standard email clients, and applied with git am while preserving full commit information including author and date.
Cover letters (--cover-letter) provide a way to introduce patch series with context. Version numbering with -v supports iterative review cycles. The signoff option adds Signed-off-by trailers for Developer Certificate of Origin compliance.

PARAMETERS

-n

Number of commits.
-o, --output-directory dir
Output directory.
--stdout
Output to stdout.
--cover-letter
Generate cover letter.
-s, --signoff
Add Signed-off-by.
--subject-prefix prefix
Subject prefix.
-v, --reroll-count n
Version number.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community