What is the difference between git am and git apply?

git apply is for applying straight diffs (e.g. from git diff) whereas git am is for applying patches and sequences of patches from emails, either mbox or Maildir format and is the "opposite" of git format-patch. git am tries to extract commit messages and author details from email messages which is why it can make commits.


Both the input and output are different:

  • git apply takes a patch (e.g. the output of git diff) and applies it to the working directory (or index, if --index or --cached is used).
  • git am takes a mailbox of commits formatted as an email messages (e.g. the output of git format-patch) and applies them to the current branch.

git am uses git apply behind the scenes, but does more work before (reading a Maildir or mbox, and parsing email messages) and after (creating commits).

Tags:

Git

Patch