git apply and git am¶
git apply and git am are commands used to apply changes from patch files to a Git repository.^[600-developer-tools-git-git-patch-cherry-pick.md]
Workflow¶
After generating patch files (e.g., using git format-patch) and copying them into the target Git directory, the workflow typically involves checking the patch status and verifying compatibility before applying the changes.^[600-developer-tools-git-git-patch-cherry-pick.md]
git apply¶
git apply is used to read a patch file and apply its changes to the current working directory, but it does not create a commit.^[600-developer-tools-git-git-patch-cherry-pick.md]
Common usage includes:
* Check statistics: git apply --stat <patch_file> displays a summary of the changes contained in the patch.^[600-developer-tools-git-git-patch-cherry-pick.md]
* Test application: git apply --check <patch_file> verifies if the patch can be applied cleanly without errors.^[600-developer-tools-git-git-patch-cherry-pick.md]
git am¶
git am (apply mailbox) applies a patch generated by git format-patch and creates a commit.^[600-developer-tools-git-git-patch-cherry-pick.md]
- Apply and sign:
git am -s < <patch_file>applies the patch and creates a commit with a "Signed-off-by" line.^[600-developer-tools-git-git-patch-cherry-pick.md]
Related Concepts¶
- git format-patch
- git cherry-pick
- [[Patch file]]
Sources¶
600-developer-tools-git-git-patch-cherry-pick.md