How can I generate a Git patch for a specific commit?
format-patch, git, patch
Solution
Try:
git format-patch -<n> <rev>
For example:
git format-patch -1 HEAD
The `-1` flag indicates how many commits should be included in the patch:
-<n>
Prepare patches from the topmost <n> commits.
Apply the patch with the command:
git am < file.patch
Alternatively you can also apply (should work on all OSes including Windows) with:
git apply --verbose file.patch
The `-v` or `--verbose` will show what failed, if any. Giving you a clue on how to fix.
Problem
I want to create a patch for a specific commit hash, `<rev>`. I tried using `git format-patch <rev>`, but that generated a patch for each commit since the `<rev>` commit. Is there a way to generate a patch only for `<rev>`?