Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Git apply vs git am

+7
−0

What are the differences between git apply and git am commands? Both seem to be used for applying patches to repositories.

When should one be used over the other?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+7
−0

Each of them has an analog to another Git command. But instead of objects in the repository, these take text file(s) created either by you or someone else.

git apply

Think of this as Applying a git stash from a text file.

Applies a delta to your worktree. It's nominally a Git-flavored version of GNU patch that uses Git's diff machinery. This command can take diffs from several formats, making it more versatile than git am but less powerful.

git am

Think of this as Cherry-picking a commit range from text file(s).

Applies commits to your HEAD. This could be a single commit or a series of them; keeping the same author, title, body, author date, etc.[1] It does require that the diff was generated by git format-patch or git send-email, so it's less versatile than git apply but more powerful.

Several notable projects[2] don't use public repos and pull requests for upstreaming code. Instead they share patch text for the maintainer to apply and evaluate. Usually these patches are traded by email with the git send-email command. I suspect that the original mnemonic for git am was "Git apply [from] mailbox."

When to use

git am

  • When you want attribution and metadata.
  • When you want a series of commits.

git apply

  • When you want to tinker with the delta before committing.
  • When the diff is not from git format-patch or git send-email.

  1. git am keeps the original author and author date, but the committer and committer date are set to you and now, respectively. This means that your commit hash will be different from the patch creator's. If your commits of their code become canonical, they will want to rebase or make new branches from your canonical version. ↩︎

  2. Notable projects maintained by email include the Linux kernel and Git itself. You can browse the Git mailing list history to see patches and commentary. Any thread with [PATCH ... ] in the subject line is a prospective commit series and discussion on it. ↩︎

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »