What is the difference between git am and git?

Both types of git am and git apply can be used to apply fixes. I do not see the difference. Now I see the difference: git am automatically committed, while git apply only applies to files, but does not create a commit. Is that the only difference?

+84
git patch
Sep 02 '12 at 10:10
source share
3 answers

Both inputs and outputs are different:

  • git apply accepts the patch (for example, git diff output) and applies it to the working directory (or index, if --index or --cached ).
  • git am takes the mailbox of commits formatted as email messages (for example, 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 (making commits).

+74
Sep 02
source share

git apply intended to apply direct differences (for example, from git diff ), while git am designed to apply patches and patch sequences from letters, either in mbox format or in Maildir format, and is the "opposite" of git format-patch . git am trying to retrieve commit messages and author data from email messages, so it can commit.

+9
Sep 02 '12 at 22:21
source share

With git am you apply the patch, so if you use git status you will not see local changes.

git apply allows you to make changes to the source files as if you were writing the code yourself, so git status and git diff will output the changes made to the fix that you applied, then you can fix / add new changes and submit them together as one new patch.

+6
02 Sep '12 at 22:20
source share



All Articles