LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

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
Create numbered, threaded patches with base info
$ git format-patch --numbered --thread --base=auto [commit]
copy
Add email recipients to patches
$ git format-patch --to=[maintainer@example.com] --cc=[list@example.com] -[3]
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, --numbered

Name output in [PATCH n/m] format.
-N, --no-numbered
Name output in [PATCH] format without numbers.
-o, --output-directory dir
Output directory for patch files.
--stdout
Output all patches to stdout instead of files.
--cover-letter
Generate a cover letter template for the patch series.
-s, --signoff
Add Signed-off-by trailer.
--subject-prefix prefix
Use given prefix instead of [PATCH].
-v, --reroll-count n
Mark patches as vn of the series (e.g., [PATCH v2]).
--thread[=style]
Generate In-Reply-To and References headers. Style: shallow (default) or deep.
--in-reply-to message-id
Make first mail appear as a reply to given message.
--to email
Add To: header to patches. Can be used multiple times.
--cc email
Add Cc: header to patches. Can be used multiple times.
--base[=commit]
Record base tree info. Use "auto" for automatic selection.
--no-stat
Generate plain patches without diffstats.
--no-binary
Do not output binary file contents, only note changes.
--interdiff previous
Insert interdiff into cover letter comparing to previous version.
--range-diff previous
Insert range-diff into cover letter comparing to previous version.
--filename-max-length n
Limit generated filenames to around n bytes (default: 64).

SEE ALSO

Copied to clipboard
Kai