info > GIT-APPLY(1)

πŸ“› NAME

git-apply – Apply a patch to files and/or to the index

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ”΅ Apply a patch to filesgit apply patch.diffApply patch to working tree (no index involved)
πŸ”΅ Apply patch to index and working treegit apply --index patch.diffAlso update the index
πŸ”΅ Apply patch to index onlygit apply --cached patch.diffLeave working tree untouched
πŸ”΅ Check if patch applies cleanlygit apply --check patch.diffDry‑run, detect errors
πŸ”΅ Show diffstat instead of applyinggit apply --stat patch.diffSummary of changes
πŸ”΅ Apply in reversegit apply -R patch.diffUndo a patch
πŸ”΅ Apply with 3‑way mergegit apply --3way patch.diffAttempt merge if blobs are available
πŸ”΅ Apply to a different directorygit apply --directory=modules/git-gui patch.diffPrepend root to filenames

πŸ“‹ SYNOPSIS

git apply [--stat] [--numstat] [--summary] [--check] [--index | --intent-to-add] [--3way]
          [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]
          [--allow-binary-replacement | --binary] [--reject] [-z]
          [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]
          [--ignore-space-change | --ignore-whitespace]
          [--whitespace=(nowarn|warn|fix|error|error-all)]
          [--exclude=<path>] [--include=<path>] [--directory=<root>]
          [--verbose] [--unsafe-paths] [<patch>...]

πŸ“– DESCRIPTION

Reads the supplied diff output (i.e. "a patch") and applies it to files. When running from a subdirectory in a repository, patched paths outside the directory are ignored. With the --index option the patch is also applied to the index, and with the --cached option the patch is only applied to the index. Without these options, the command applies the patch only to files, and does not require them to be in a Git repository.

This command applies the patch but does not create a commit. Use git-am(1) to create commits from patches generated by git-format-patch(1) and/or received by email.

βš™οΈ OPTIONS

βš™οΈ CONFIGURATION

πŸ“Œ SUBMODULES

If the patch contains any changes to submodules then git apply treats these changes as follows.

If --index is specified (explicitly or implicitly), then the submodule commits must match the index exactly for the patch to apply. If any of the submodules are checked‑out, then these check‑outs are completely ignored, i.e., they are not required to be up to date or clean and they are not updated.

If --index is not specified, then the submodule commits in the patch are ignored and only the absence or presence of the corresponding subdirectory is checked and (if possible) updated.

πŸ”— SEE ALSO

git-am(1).

πŸ“š GIT

Part of the git(1) suite

GIT-APPLY(1)
πŸ“› NAME πŸš€ Quick Reference πŸ“‹ SYNOPSIS πŸ“– DESCRIPTION βš™οΈ OPTIONS βš™οΈ CONFIGURATION πŸ“Œ SUBMODULES πŸ”— SEE ALSO πŸ“š GIT

Generated by phpman v4.9.25-8-g32d6339 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-13 03:47 @216.73.217.22
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format

^_top_^