<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="git-am(1)">
    <title>git-am(1)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>git-am(1)</primary>
</indexterm>
<simplesect id="git-am(1)__name">
<title>NAME</title>
<simpara>git-am - Apply a series of patches from a mailbox</simpara>
</simplesect>
<simplesect id="git-am(1)__synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git am</emphasis> [--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=&lt;action&gt;] [-C&lt;n&gt;] [-p&lt;n&gt;] [--directory=&lt;dir&gt;]
         [--exclude=&lt;path&gt;] [--include=&lt;path&gt;] [--reject] [-q | --quiet]
         [--[no-]scissors] [-S[&lt;keyid&gt;]] [--patch-format=&lt;format&gt;]
         [--quoted-cr=&lt;action&gt;]
         [--empty=(stop|drop|keep)]
         [(&lt;mbox&gt; | &lt;Maildir&gt;)&#8230;]
<emphasis>git am</emphasis> (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)] | --allow-empty)</literallayout>
</blockquote>
</simplesect>
<simplesect id="git-am(1)__description">
<title>DESCRIPTION</title>
<simpara>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 <xref linkend="git-format-patch(1)" /> run on a branch with a straight
history without merges.</simpara>
</simplesect>
<simplesect id="git-am(1)__options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
(&lt;mbox&gt;|&lt;Maildir&gt;)&#8230;
</term>
<listitem>
<simpara>
        The list of mailbox files to read patches from. If you do not
        supply this argument, the command reads from the standard input.
        If you supply directories, they will be treated as Maildirs.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-s
</term>
<term>
--signoff
</term>
<listitem>
<simpara>
        Add a <emphasis>Signed-off-by</emphasis> trailer to the commit message, using
        the committer identity of yourself.
        See the signoff option in <xref linkend="git-commit(1)" /> for more information.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-k
</term>
<term>
--keep
</term>
<listitem>
<simpara>
        Pass <emphasis>-k</emphasis> flag to <emphasis>git mailinfo</emphasis> (see <xref linkend="git-mailinfo(1)" />).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--keep-non-patch
</term>
<listitem>
<simpara>
        Pass <emphasis>-b</emphasis> flag to <emphasis>git mailinfo</emphasis> (see <xref linkend="git-mailinfo(1)" />).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--[no-]keep-cr
</term>
<listitem>
<simpara>
        With <emphasis>--keep-cr</emphasis>, call <emphasis>git mailsplit</emphasis> (see <xref linkend="git-mailsplit(1)" />)
        with the same option, to prevent it from stripping CR at the end of
        lines. <emphasis>am.keepcr</emphasis> configuration variable can be used to specify the
        default behaviour.  <emphasis>--no-keep-cr</emphasis> is useful to override <emphasis>am.keepcr</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-c
</term>
<term>
--scissors
</term>
<listitem>
<simpara>
        Remove everything in body before a scissors line (see
        <xref linkend="git-mailinfo(1)" />). Can be activated by default using
        the <emphasis>mailinfo.scissors</emphasis> configuration variable.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-scissors
</term>
<listitem>
<simpara>
        Ignore scissors lines (see <xref linkend="git-mailinfo(1)" />).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--quoted-cr=&lt;action&gt;
</term>
<listitem>
<simpara>
        This flag will be passed down to <emphasis>git mailinfo</emphasis> (see <xref linkend="git-mailinfo(1)" />).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--empty=(drop|keep|stop)
</term>
<listitem>
<simpara>
        How to handle an e-mail message lacking a patch:
</simpara>
<variablelist>
<varlistentry>
<term>
<emphasis>drop</emphasis>
</term>
<listitem>
<simpara>
        The e-mail message will be skipped.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis>keep</emphasis>
</term>
<listitem>
<simpara>
        An empty commit will be created, with the contents of the e-mail
        message as its log.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<emphasis>stop</emphasis>
</term>
<listitem>
<simpara>
        The command will fail, stopping in the middle of the current <emphasis>am</emphasis>
        session. This is the default behavior.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
<varlistentry>
<term>
-m
</term>
<term>
--message-id
</term>
<listitem>
<simpara>
        Pass the <emphasis>-m</emphasis> flag to <emphasis>git mailinfo</emphasis> (see <xref linkend="git-mailinfo(1)" />),
        so that the Message-ID header is added to the commit message.
        The <emphasis>am.messageid</emphasis> configuration variable can be used to specify
        the default behaviour.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-message-id
</term>
<listitem>
<simpara>
        Do not add the Message-ID header to the commit message.
        <emphasis>no-message-id</emphasis> is useful to override <emphasis>am.messageid</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-q
</term>
<term>
--quiet
</term>
<listitem>
<simpara>
        Be quiet. Only print error messages.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-u
</term>
<term>
--utf8
</term>
<listitem>
<simpara>
        Pass <emphasis>-u</emphasis> flag to <emphasis>git mailinfo</emphasis> (see <xref linkend="git-mailinfo(1)" />).
        The proposed commit log message taken from the e-mail
        is re-coded into UTF-8 encoding (configuration variable
        <emphasis>i18n.commitEncoding</emphasis> can be used to specify the project's
        preferred encoding if it is not UTF-8).
</simpara>
<simpara>This was optional in prior versions of git, but now it is the
default.   You can use <emphasis>--no-utf8</emphasis> to override this.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-utf8
</term>
<listitem>
<simpara>
        Pass <emphasis>-n</emphasis> flag to <emphasis>git mailinfo</emphasis> (see
        <xref linkend="git-mailinfo(1)" />).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-3
</term>
<term>
--3way
</term>
<term>
--no-3way
</term>
<listitem>
<simpara>
        When the patch does not apply cleanly, fall back on
        3-way merge if the patch records the identity of blobs
        it is supposed to apply to and we have those blobs
        available locally. <emphasis>--no-3way</emphasis> can be used to override
        am.threeWay configuration variable. For more information,
        see am.threeWay in <xref linkend="git-config(1)" />.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--rerere-autoupdate
</term>
<term>
--no-rerere-autoupdate
</term>
<listitem>
<simpara>
        After the rerere mechanism reuses a recorded resolution on
        the current conflict to update the files in the working
        tree, allow it to also update the index with the result of
        resolution.  <emphasis>--no-rerere-autoupdate</emphasis> is a good way to
        double-check what <emphasis>rerere</emphasis> did and catch potential
        mismerges, before committing the result to the index with a
        separate <emphasis>git add</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--ignore-space-change
</term>
<term>
--ignore-whitespace
</term>
<term>
--whitespace=&lt;action&gt;
</term>
<term>
-C&lt;n&gt;
</term>
<term>
-p&lt;n&gt;
</term>
<term>
--directory=&lt;dir&gt;
</term>
<term>
--exclude=&lt;path&gt;
</term>
<term>
--include=&lt;path&gt;
</term>
<term>
--reject
</term>
<listitem>
<simpara>
        These flags are passed to the <emphasis>git apply</emphasis> (see <xref linkend="git-apply(1)" />)
        program that applies
        the patch.
</simpara>
<simpara>Valid &lt;action&gt; for the <emphasis>--whitespace</emphasis> option are:
<emphasis>nowarn</emphasis>, <emphasis>warn</emphasis>, <emphasis>fix</emphasis>, <emphasis>error</emphasis>, and <emphasis>error-all</emphasis>.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--patch-format
</term>
<listitem>
<simpara>
        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.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-i
</term>
<term>
--interactive
</term>
<listitem>
<simpara>
        Run interactively.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-n
</term>
<term>
--no-verify
</term>
<listitem>
<simpara>
        By default, the pre-applypatch and applypatch-msg hooks are run.
        When any of <emphasis>--no-verify</emphasis> or <emphasis>-n</emphasis> is given, these are bypassed.
        See also <xref linkend="githooks(5)" />.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--committer-date-is-author-date
</term>
<listitem>
<simpara>
        By default the command records the date from the e-mail
        message as the commit author date, and uses the time of
        commit creation as the committer date. This allows the
        user to lie about the committer date by using the same
        value as the author date.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--ignore-date
</term>
<listitem>
<simpara>
        By default the command records the date from the e-mail
        message as the commit author date, and uses the time of
        commit creation as the committer date. This allows the
        user to lie about the author date by using the same
        value as the committer date.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--skip
</term>
<listitem>
<simpara>
        Skip the current patch.  This is only meaningful when
        restarting an aborted patch.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
-S[&lt;keyid&gt;]
</term>
<term>
--gpg-sign[=&lt;keyid&gt;]
</term>
<term>
--no-gpg-sign
</term>
<listitem>
<simpara>
        GPG-sign commits. The <emphasis>keyid</emphasis> argument is optional and
        defaults to the committer identity; if specified, it must be
        stuck to the option without a space. <emphasis>--no-gpg-sign</emphasis> is useful to
        countermand both <emphasis>commit.gpgSign</emphasis> configuration variable, and
        earlier <emphasis>--gpg-sign</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--continue
</term>
<term>
-r
</term>
<term>
--resolved
</term>
<listitem>
<simpara>
        After a patch failure (e.g. attempting to apply
        conflicting patch), the user has applied it by hand and
        the index file stores the result of the application.
        Make a commit using the authorship and commit log
        extracted from the e-mail message and the current index
        file, and continue.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--resolvemsg=&lt;msg&gt;
</term>
<listitem>
<simpara>
        When a patch failure occurs, &lt;msg&gt; will be printed
        to the screen before exiting.  This overrides the
        standard message informing you to use <emphasis>--continue</emphasis>
        or <emphasis>--skip</emphasis> to handle the failure.  This is solely
        for internal use between <emphasis>git rebase</emphasis> and <emphasis>git am</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--abort
</term>
<listitem>
<simpara>
        Restore the original branch and abort the patching operation.
        Revert the contents of files involved in the am operation to their
        pre-am state.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--quit
</term>
<listitem>
<simpara>
        Abort the patching operation but keep HEAD and the index
        untouched.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--show-current-patch[=(diff|raw)]
</term>
<listitem>
<simpara>
        Show the message at which <emphasis>git am</emphasis> has stopped due to
        conflicts.  If <emphasis>raw</emphasis> is specified, show the raw contents of
        the e-mail message; if <emphasis>diff</emphasis>, show the diff portion only.
        Defaults to <emphasis>raw</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--allow-empty
</term>
<listitem>
<simpara>
        After a patch failure on an input e-mail message lacking a patch,
        create an empty commit with the contents of the e-mail message
        as its log message.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-am(1)__discussion">
<title>DISCUSSION</title>
<simpara>The commit author name is taken from the "From: " line of the
message, and commit author date is taken from the "Date: " line
of the message.  The "Subject: " line is used as the title of
the commit, after stripping common prefix "[PATCH &lt;anything&gt;]".
The "Subject: " line is supposed to concisely describe what the
commit is about in one line of text.</simpara>
<simpara>"From: ", "Date: ", and "Subject: " lines starting the body override the
respective commit author name and title values taken from the headers.</simpara>
<simpara>The commit message is formed by the title taken from the
"Subject: ", a blank line and the body of the message up to
where the patch begins.  Excess whitespace at the end of each
line is automatically stripped.</simpara>
<simpara>The patch is expected to be inline, directly following the
message.  Any line that is of the form:</simpara>
<itemizedlist>
<listitem>
<simpara>
three-dashes and end-of-line, or
</simpara>
</listitem>
<listitem>
<simpara>
a line that begins with "diff -", or
</simpara>
</listitem>
<listitem>
<simpara>
a line that begins with "Index: "
</simpara>
</listitem>
</itemizedlist>
<simpara>is taken as the beginning of a patch, and the commit log message
is terminated before the first occurrence of such a line.</simpara>
<simpara>When initially invoking <emphasis>git am</emphasis>, you give it the names of the mailboxes
to process.  Upon seeing the first patch that does not apply, it
aborts in the middle.  You can recover from this in one of two ways:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
skip the current patch by re-running the command with the <emphasis>--skip</emphasis>
  option.
</simpara>
</listitem>
<listitem>
<simpara>
hand resolve the conflict in the working directory, and update
  the index file to bring it into a state that the patch should
  have produced.  Then run the command with the <emphasis>--continue</emphasis> option.
</simpara>
</listitem>
</orderedlist>
<simpara>The command refuses to process new mailboxes until the current
operation is finished, so if you decide to start over from scratch,
run <emphasis>git am --abort</emphasis> before running the command with mailbox
names.</simpara>
<simpara>Before any patches are applied, ORIG_HEAD is set to the tip of the
current branch.  This is useful if you have problems with multiple
commits, like running <emphasis>git am</emphasis> on the wrong branch or an error in the
commits that is more easily fixed by changing the mailbox (e.g.
errors in the "From:" lines).</simpara>
</simplesect>
<simplesect id="git-am(1)__hooks">
<title>HOOKS</title>
<simpara>This command can run <emphasis>applypatch-msg</emphasis>, <emphasis>pre-applypatch</emphasis>,
and <emphasis>post-applypatch</emphasis> hooks.  See <xref linkend="githooks(5)" /> for more
information.</simpara>
</simplesect>
<simplesect id="git-am(1)__configuration">
<title>CONFIGURATION</title>
<simpara>Everything below this line in this section is selectively included
from the <xref linkend="git-config(1)" /> documentation. The content is the same
as what's found there:</simpara>
<variablelist>
<varlistentry>
<term>
am.keepcr
</term>
<listitem>
<simpara>
        If true, git-am will call git-mailsplit for patches in mbox format
        with parameter <emphasis>--keep-cr</emphasis>. In this case git-mailsplit will
        not remove <emphasis>\r</emphasis> from lines ending with <emphasis>\r\n</emphasis>. Can be overridden
        by giving <emphasis>--no-keep-cr</emphasis> from the command line.
        See <xref linkend="git-am(1)" />, <xref linkend="git-mailsplit(1)" />.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
am.threeWay
</term>
<listitem>
<simpara>
        By default, <emphasis>git am</emphasis> will fail if the patch does not apply cleanly. When
        set to true, this setting tells <emphasis>git am</emphasis> to fall back on 3-way merge if
        the patch records the identity of blobs it is supposed to apply to and
        we have those blobs available locally (equivalent to giving the <emphasis>--3way</emphasis>
        option from the command line). Defaults to <emphasis>false</emphasis>.
        See <xref linkend="git-am(1)" />.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-am(1)__see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-apply(1)" />,
<xref linkend="git-format-patch(1)" />.</simpara>
</simplesect>
<simplesect id="git-am(1)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
