git apply
git
Usage
git apply [--check|-3] <patch>Applies a diff file to your working tree; it makes no commit and ignores the author recorded in the patch, so mailed patches belong to am instead.
Common flags
| Flag | Meaning |
|---|---|
| --check | report whether it would apply, change nothing |
| -3 | fall back to a three-way merge and leave conflict markers |
| --index | apply to the working tree and stage it |
| --cached | apply to the index only |
| -R | apply in reverse, undoing the patch |
| -p<n> | strip n leading path components |
| --stat | show what the patch touches |
Examples
git apply --check fix.patchtells you if it fits before you try
git apply -3 fix.patchapplies it and leaves conflicts to resolve by hand
git apply -R fix.patchtakes an applied patch back out
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git apply do?
Applies a diff file to your working tree; it makes no commit and ignores the author recorded in the patch, so mailed patches belong to am instead.
Q. How do I type it?
git apply [--check|-3] <patch> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-apply