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?
Git – the difference between git am and git apply
gitpatch
Related Topic
- Git – the difference between ‘git pull’ and ‘git fetch’
- Git – How to undo the most recent local commits in Git
- Git – How to find and restore a deleted file in a Git repository
- Git: How to force “git pull” to overwrite local files
- Git – Remove a file from a Git repository without deleting it from the local filesystem
- Git – How to delete a Git branch locally and remotely
- Git – How to change the URI (URL) for a remote Git repository
- Git – How to push a new local branch to a remote Git repository and track it too
Best Answer
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
usesgit apply
behind the scenes, but does more work before (reading aMaildir
ormbox
, and parsing email messages) and after (creating commits).