Git
简体中文 ▾ Topics ▾ Latest version ▾ git-am last updated in 2.44.0

名称

git-am - Apply a series of patches from a mailbox

概述

git am [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8] [--no-verify]
	 [--[no-]3way] [--interactive] [--committer-date-is-author-date]
	 [--ignore-date] [--ignore-space-change | --ignore-whitespace]
	 [--whitespace=<action>] [-C<n>] [-p<n>] [--directory=<dir>]
	 [--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
	 [--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
	 [--quoted-cr=<action>]
	 [--empty=(stop|drop|keep)]
	 [(<mbox> | <Maildir>)…​]
git am (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)] | --allow-empty)

描述

Splits mail messages in a mailbox into commit log messages, authorship information, and patches, and applies them to the current branch. You could think of it as a reverse operation of git-format-patch[1] run on a branch with a straight history without merges.

选项

(<mbox>|<Maildir>)…​

要读取补丁的邮箱文件的列表。如果你不提供这个参数,命令将从标准输入中读取。 如果你提供目录,它们将被视为邮箱目录。

-s
--signoff

在提交信息中加入 Signed-off-by 的尾注,使用自己的提交者身份。 更多信息见 git-commit[1] 中的 signoff 选项。

-k
--keep

传递`-k` 标志给 git mailinfo(见git-mailinfo[1])。

--keep-non-patch

-b 标志传递给 git mailinfo(见git-mailinfo[1])。

--[no-]keep-cr

使用 --keep-cr,调用 git mailsplit(见git-mailsplit[1]),并使用相同的选项,以防止它在行末剥离 CR。am.keepcr 配置变量可以用来指定默认行为。 --no-keep-cr 可以用来覆盖 am.keepcr

-c
--scissors

移除正文中剪切行之前的所有内容(见git-mailinfo[1])。可以使用 mailinfo.scissors 配置变量来默认激活。

--no-scissors

忽略剪切线(见git-mailinfo[1])。

--quoted-cr=<action>

这个标志将被传递给 git mailinfo(见 git-mailinfo[1])。

--empty=(stop|drop|keep)

By default, or when the option is set to stop, the command errors out on an input e-mail message lacking a patch and stops in the middle of the current am session. When this option is set to drop, skip such an e-mail message instead. When this option is set to keep, create an empty commit, recording the contents of the e-mail message as its log.

-m
--message-id

传递 -m 标志给 git mailinfo(见 git-mailinfo[1]),这样 Message-ID 头会被添加到提交信息中。 am.messageid 配置变量可以用来指定默认行为。

--no-message-id

不要在提交信息中添加 Message-ID 头。 no-message-id 对于覆盖 am.messageid 很有用。

-q
--quiet

保持安静。只打印错误信息。

-u
--utf8

Pass -u flag to git mailinfo (see git-mailinfo[1]). The proposed commit log message taken from the e-mail is re-coded into UTF-8 encoding (configuration variable i18n.commitEncoding can be used to specify the project’s preferred encoding if it is not UTF-8).

这在以前的 git 版本中是可选的,但现在它是 默认的。 你可以使用 --no-utf8 来覆盖它。

--no-utf8

传递 -n 标志给 git mailinfo(见git-mailinfo[1])。

-3
--3way
--no-3way

当补丁不能干净地应用时,如果补丁记录了它应该应用到的二进制文件的身份,并且我们有这些二进制文件可以在本地使用,那么就退回到三路合并。--no-3way 可以用来覆盖 am.threeWay 配置变量。更多信息,见 git-config[1] 中的 am.threeWay。

--rerere-autoupdate
--no-rerere-autoupdate

在 rerere 机制重用当前冲突的记录解析来更新工作树中的文件后,允许它也用解析的结果来更新索引。 --no-rerere-autoupdate`是一个很好的方法,在用单独的 `git add 提交结果到索引之前,可以反复检查 rerere 所做的事情,并抓住潜在的错误合并。

--ignore-space-change
--ignore-whitespace
--whitespace=<action>
-C<n>
-p<n>
--directory=<dir>
--exclude=<路径>
--include=<path>
--reject

这些标志会传递给应用补丁的 "git apply"(见 git-apply[1])程序。

--patch-format

By default the command will try to detect the patch format automatically. This option allows the user to bypass the automatic detection and specify the patch format that the patch(es) should be interpreted as. Valid formats are mbox, mboxrd, stgit, stgit-series, and hg.

-i
--interactive

交互式运行。

-n
--no-verify

By default, the pre-applypatch and applypatch-msg hooks are run. When any of --no-verify or -n is given, these are bypassed. See also githooks[5].

--committer-date-is-author-date

默认情况下,该命令将电子邮件中的日期作为提交者日期,并使用提交者的创建时间作为提交者日期。这使得用户可以通过使用与作者日期相同的值来谎报提交者日期。

--ignore-date

默认情况下,该命令将电子邮件中的日期作为提交者日期,并使用提交者的创建时间作为提交者日期。这使得用户可以通过使用与提交者日期相同的值来谎报作者日期。

--skip

跳过当前的补丁。 这只有在重新启动一个中止的补丁时才有意义。

-S[<keyid>]
--gpg-sign[=<keyid>]
--no-gpg-sign

GPG 签名提交。keyid 参数是可选的,默认为提交者身份;如果指定了,则必须与选项相连,不加空格。--no-gpg-sign 用于还原 commit.gpgSign 配置变量和先前的 --gpg-sign

--continue
-r
--resolved

补丁失败后(如试图应用冲突的补丁),用户已经手工应用,索引文件存储了应用的结果。 使用从电子邮件中提取的作者和提交日志以及当前的索引文件进行提交,然后继续运行。

--resolvemsg=<msg>

当发生补丁失败时,<信息> 将在退出前被打印到屏幕上。 这将覆盖标准信息,通知你使用 --continue--skip 来处理失败。 这只是为了在 git rebasegit am 之间的内部使用。

--abort

Restore the original branch and abort the patching operation. Revert the contents of files involved in the am operation to their pre-am state.

--quit

中止打补丁的操作,但保留 HEAD 和索引不被接触。

--show-current-patch[=(diff|raw)]

显示`git am` 因冲突而停止的消息。 如果指定了 raw,显示电子邮件的原始内容;如果是 diff,只显示差异部分。 默认为 raw

--allow-empty

在对缺乏补丁的输入邮件信息进行补丁失败后,创建一个空的提交,将邮件信息的内容作为其日志信息。

讨论

提交者的名字取自信息的 "From:" 行,而提交者的日期则取自信息的 "Date:" 行。 "Subject:" 行是提交的标题,在去掉普通前缀 "[PATCH <任何东西>]" 之后。 "Sbuject: " 是为了用一行文字简洁地描述提交的内容。

"From: "、"Date: " 和 "Subject: " 行开始的正文覆盖了从标题中获取的各自的提交者名称和标题值。

提交信息由 "Subject: " 中的标题、一个空行和直到补丁开始的信息正文组成。 每行末尾多余的空格会被自动删除。

补丁应该是内联的,直接跟在信息后面。 任何形式的行:

  • 三个破折号和行末,或

  • 以 "diff - " 开头的一行,或

  • 以 "index: " 开头的一行

被认为是一个补丁的开始,提交日志信息在第一次出现这样的行之前就结束了。

当最初调用 git am 时,你给了它要处理的邮箱的名字。 当看到第一个不适用的补丁时,它就会在中间中止。 你可以通过以下两种方式之一恢复:

  1. 通过重新运行带有 --skip 选项的命令,跳过当前补丁。

  2. 手解决工作目录中的冲突,并更新索引文件,使其进入补丁应该产生的状态。 然后用 --continue 选项运行该命令。

在当前操作完成之前,该命令拒绝处理新的邮箱,所以如果你决定从头开始,在运行带有邮箱名称的命令之前,运行 git am --abort

在应用任何补丁之前,ORIG_HEAD 被设置为当前分支的顶端。 如果你在多个提交中遇到问题,比如在错误的分支上运行 git am,或者提交中的错误更容易通过改变邮箱来解决(比如 "From: " 行中的错误),这就很有用了。

HOOKS

这个命令可以运行 applypatch-msg, pre-applypatch, 和 post-applypatch 钩子。 更多信息见 githooks[5]

配置

Warning

Missing zh_HANS-CN/includes/cmd-config-section-all.txt

See original version for this content.

Warning

Missing zh_HANS-CN/config/am.txt

See original version for this content.

GIT

属于 git[1] 文档

scroll-to-top