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.
git am [options] [<mbox> | <Maildir>...] git am (--continue | --skip | --abort | --quit | --show-current-patch[=diff|raw])
Try it
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.
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 ofamrefuses a rebase and some other commands. - Strictness.
amapplies a patch only if the context matches exactly. That is why--3wayis 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 rungit apply --reject),git addthem, thengit am --continue. - Not for plain diffs. If the file is just
git diffoutput without mail headers, there is no author or message; use git apply and commit yourself. - Signing. Commits created by
amare signed ifcommit.gpgSignis on, and-Ssigns explicitly. - Line endings. Patches that cross CRLF boundaries often fail on whitespace. Try
--ignore-whitespace(same asgit apply) or normalize first. - Mail clients may mangle patches (wrapped lines, converted tabs). Prefer
git send-emailor attachments.