git format-patch

git

書き方

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

コミットごとにメール形式の.patchファイルを一つ書き出します。format-patch mainはmain自身ではなく、main以降のコミットを指します。

よく使うオプション

オプション意味
-<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

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

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git format-patch は何をしますか。

コミットごとにメール形式の.patchファイルを一つ書き出します。format-patch mainはmain自身ではなく、main以降のコミットを指します。

Q. どう打ちますか。

git format-patch [-<n>|<since>] [-o <dir>] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-format-patch