git format-patch --help
GIT-FORMAT-PATCH(1) Git Manual GIT-FORMAT-PATCH(1)
NAME
git-format-patch - Prepare patches for e-mail submission
SYNOPSIS
git format-patch [-k] [(-o|--output-directory) <dir> | --stdout]
[--no-thread | --thread[=<style>]]
[(--attach|--inline)[=<boundary>] | --no-attach]
[-s | --signoff]
[--signature=<signature> | --no-signature]
[-n | --numbered | -N | --no-numbered]
[--start-number <n>] [--numbered-files]
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
[--ignore-if-in-upstream]
[--subject-prefix=Subject-Prefix]
[--to=<email>] [--cc=<email>]
[--cover-letter]
[<common diff options>]
[ <since> | <revision range> ]
DESCRIPTION
Prepare each commit with its patch in one file per commit, formatted to resemble UNIX mailbox format. The output of this command is convenient for
e-mail submission or for use with git am.
There are two ways to specify which commits to operate on.
1. A single commit, <since>, specifies that the commits leading to the tip of the current branch that are not in the history that leads to the
<since> to be output.
2. Generic <revision range> expression (see "SPECIFYING REVISIONS" section in gitrevisions(7)) means the commits in the specified range.
The first rule takes precedence in the case of a single <commit>.
To apply the second rule, i.e., format everything since the beginning of history
up until <commit>, use the --root option: git format-patch --root <commit>.
If you want to format only <commit> itself, you can do this with git
format-patch -1 <commit>.
By default, each output file is numbered sequentially from 1, and uses the first line of the commit message (massaged for pathname safety) as the
filename. With the --numbered-files option, the output file names will only be numbers, without the first line of the commit appended. The names
of the output files are printed to standard output, unless the --stdout option is specified.
If -o is specified, output files are created in <dir>. Otherwise they are created in the current working directory.
By default, the subject of a single patch is "[PATCH] First Line" and the subject when multiple patches are output is "[PATCH n/m] First Line". To
force 1/1 to be added for a single patch, use -n. To omit patch numbers from the subject, use -N.
If given --thread, git-format-patch will generate In-Reply-To and References headers to make the second and subsequent patch mails appear as
replies to the first mail; this also generates a Message-Id header to reference.
假如有下面的git history:
$ git log --date=short --stat
commit 0c0d1f8a15182e1b3f1b993cbb656aa1011df03a
Author: xxxx <xxxx@gmail.com>
Date: 2013-04-30
Git V3 test.
Signed-off-by: xxxx <xxxx@gmail.com>
main.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
commit eaac65848e35f79d44c8812d787a8846bc3b085d
Author: xxxx <xxxx@xxxx-laptop.(none)>
Date: 2013-04-30
Git test V2.
main.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
commit 4292481bb3800f99ab0686061bc1f5edd15d314c
Author: xxxx <xxxx@xxxx-laptop.(none)>
Date: 2013-03-25
Add main.c
Signed-off-by: xxxx <xxxx@xxxx-laptop.(none)>
main.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
1.
$ git format-patch -1 0c0d1f8a15182e1b3f1b993cbb656aa1011df03a
将 0c0d1f8a15182e1b3f1b993cbb656aa1011df03a 这个commit 生成 patch.
2.
$ git format-patch --root 0c0d1f8a15182e1b3f1b993cbb656aa1011df03a
将 git 从第一个commit 提交开始到 0c0d1f8a15182e1b3f1b993cbb656aa1011df03a 的所有 commit 生成patch.
3.
$ git format-patch 4292481bb3800f99ab0686061bc1f5edd15d314c..0c0d1f8a15182e1b3f1b993cbb656aa1011df03a
将 commit 4292481bb3800f99ab0686061bc1f5edd15d314c 到 0c0d1f8a15182e1b3f1b993cbb656aa1011df03a commit 之间的所有commit 生成 patch.
需要注意的是,这个区间是(4292481bb3800f99ab0686061bc1f5edd15d314c,0c0d1f8a15182e1b3f1b993cbb656aa1011df03a】,不包含前区间commit,包含后区间commit。
本文详细介绍了如何使用git format-patch命令将Git提交转换为邮件提交格式,包括指定commit范围、设置邮件主题、添加回复引用等功能,并通过示例演示了生成单个commit和多个commit的patch文件过程。
7197

被折叠的 条评论
为什么被折叠?



