Both git am
and git apply
can be used to apply patches.
I fail to see the difference. I see a difference now: git am
automatically commits whereas git apply
only touches the files but doesn't create a commit. Is that the only difference?
-
18`am` could be thought of as an abbreviation of `Apply Mail`... – Philip Oakley Sep 04 '12 at 10:05
3 Answers
Both the input and output are different:
git apply
takes a patch (e.g. the output ofgit 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 ofgit 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).

- 1,030
- 11
- 19

- 28,393
- 13
- 77
- 72
-
11Note: `git apply` seems to also accept `git format-patch` output. – Ciro Santilli OurBigBook.com Jun 24 '15 at 08:31
-
23`git apply` would work for output from `git format-patch` as well but the changes would be unstaged and would need to be committed (thus creating a different commit point in the index they are applied to). With `git am` you would be carrying the commit information (along with author, etc.) into the index it is applied to. `git apply` then is for patching your repo (bad), `git am` can take legit feature changes and include it into your repo (preferred approach). – Prasoon Joshi May 19 '17 at 13:44
-
Which of these would I normally want if I used `GITK` to view my tree and then made a patch from the context menu on my uncommitted changes? I can't imagine git am would work very well if there's no commit information for it to create the commits, so I would guess git apply is what I want.…
…I guess, both in the name of general prudence and because of the moderation strike (My trust for this site is running a little low right now, if they don't understand the problem with AI answers), I should http://www.tryitands.ee – Twisted on STRIKE at1687989253 Jun 28 '23 at 16:03 -
looks like git apply is the command to do, in the situation I described above. I would assume the same applies if I create the patch from a sequence of commands in GITK? but I don't need to know right now, so I'm not going to try it and see. Feel free to do so yourself! – Twisted on STRIKE at1687989253 Jun 28 '23 at 20:35
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.

- 755,051
- 104
- 632
- 656
With git am
you apply the patch so when you run git status
you won't see any local changes, but git log
will show the patch have been committed to the source code.
But with git apply
you make the changes in the source files as if you were writing the code yourself, consequently git status
and git diff
will output the changes appeared in the patch you applied. Hence with git apply
you can fix/add more changes and git add
them together as a single new patch.

- 39,472
- 36
- 165
- 245