Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Remotes and Collaboration

git am command

Reference for git am: apply format-patch files or mbox mail as real commits, keep authorship, resolve failures with --continue, --skip and --abort, and use --3way.

git am reads patches in email format (an mbox, a Maildir, or individual .patch files from git format-patch) and turns each one into a commit. The author name, author date and message come from the email; the committer is you.

"am" stands for "apply mailbox". It is the commit-creating counterpart of git apply, which only changes files. When a patch does not fit, am stops in the middle of a series and waits for you to fix things, much like a rebase.

Terminal
git am [options] [<mbox> | <Maildir>...]
git am (--continue | --skip | --abort | --quit | --show-current-patch[=diff|raw])

Try it

Bash Move commits between repositories

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash A patch that fails, then --3way and --abort

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Option Description
<mbox>... One or more mailbox files or Maildirs. With none, reads standard input. A directory of .patch files can be passed as *.patch.
-3, --3way If a patch does not apply cleanly, use the blob IDs in its index lines to attempt a three-way merge. Needs the base blobs in your repository.
-s, --signoff Add a Signed-off-by: trailer of the committer.
-k, --keep Keep the subject as is: do not strip [PATCH] tags. --keep-non-patch strips only non-PATCH brackets.
--no-verify / -n Skip the pre-applypatch and applypatch-msg hooks.
--directory=<dir>, -p<n>, --include, --exclude Path handling, the same as in git apply.
--whitespace=<action>, -C<n> Whitespace and context handling, passed to git apply.
--committer-date-is-author-date Use the author date as the committer date.
--empty=<action> What to do with patches that create no change: drop, keep or stop (the default).
--reject Apply what fits and write rejected hunks to .rej files.
--continue, -r, --resolved After fixing the problem and staging the files, continue the series.
--skip Skip the current patch and move on.
--abort Restore the original branch and remove the session state.
--quit Stop the session but keep the commits already made.
--show-current-patch Show the patch being applied when am stopped.

Exit status: 0 when all patches are applied; non-zero if a patch fails (the session stays open until you continue, skip or abort).

Usage notes

  • Session state lives in .git/rebase-apply. A repository in the middle of am refuses a rebase and some other commands.
  • Strictness. am applies a patch only if the context matches exactly. That is why --3way is the most useful retry flag, and why base blobs matter: fetch the sender's repository first when you can.
  • Fixing a failure. Look at git am --show-current-patch=diff, edit the files (or run git apply --reject), git add them, then git am --continue.
  • Not for plain diffs. If the file is just git diff output without mail headers, there is no author or message; use git apply and commit yourself.
  • Signing. Commits created by am are signed if commit.gpgSign is on, and -S signs explicitly.
  • Line endings. Patches that cross CRLF boundaries often fail on whitespace. Try --ignore-whitespace (same as git apply) or normalize first.
  • Mail clients may mangle patches (wrapped lines, converted tabs). Prefer git send-email or attachments.