LinuxCommandLibrary

git-apply

Apply patches to files and the index

TLDR

Apply a patch

$ git apply [patch.diff]
copy
Check if patch applies
$ git apply --check [patch.diff]
copy
Apply with stats
$ git apply --stat [patch.diff]
copy
Reverse a patch
$ git apply --reverse [patch.diff]
copy
Apply to index
$ git apply --cached [patch.diff]
copy

SYNOPSIS

git apply [options] patches

DESCRIPTION

git apply applies patches to files and/or the index. Unlike git am, it works with raw diff output without email formatting, making it suitable for patches generated by git diff.
The command can apply patches to the working tree, index, or both. It supports checking patches without applying (--check) and showing statistics (--stat). Reverse application (--reverse) enables undoing patches.
Unlike git am, this command does not create commits, making it suitable for applying patches as working directory modifications that can be reviewed before committing.

PARAMETERS

PATCHES

Patch files to apply.
--check
Check if patch applies cleanly.
--stat
Show diffstat instead of applying.
--reverse, -R
Apply patch in reverse.
--cached
Apply to index only.
--3way
Attempt 3-way merge.
-v, --verbose
Report progress.
--help
Display help information.

CAVEATS

Does not create commits. Use git am for patch series. May fail on binary files without appropriate handling.

HISTORY

git apply is a core Git command for patch application, providing lower-level functionality than git am.

SEE ALSO

git-am(1), git-diff(1), patch(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community