If I have a commit hash that has not yet been pushed to origin, how can I generate a patch for that commit only. I would like to use git log -p --no-names
but can't see a switch to pass in a specific commit hash. Should I be using a different git command?
Asked
Active
Viewed 1.8k times
28

Jonathan Day
- 18,519
- 10
- 84
- 137
1 Answers
49
For git log patch:
git log -p -1 <commit>
You should be using git format-patch
for patches though:
git format-patch -1 <commit>
http://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html

manojlds
- 290,304
- 63
- 469
- 417
-
thanks. what's the benefit of format-patch instead of `git log -p`? – Jonathan Day May 05 '11 at 03:03
-
4@Jonathan: Both suffice as a diff intended to be consumed by a human (e.g. for review), but the output of `git format-patch` encapsulates the author information and the commit message (as well as the diff text) in a standard format so that it can be reliably parsed by other tools (e.g. `git send-email` to send them as emails and `git am` to apply one or more patches (e.g. some that have been collected as received emails)). – Chris Johnsen May 05 '11 at 15:34
-
thanks @Chris that's helpful. it seems that ubuntu patch is having issues parsing the output of `git log -p` so that might be the solution – Jonathan Day May 06 '11 at 00:34
-
2@Jonathan: Git-style diffs (i.e. those with a `diff --git` header) have several extensions that regular *patch* will not understand (the format is very similar though, so it may work in many cases). You can apply plain diffs (e.g. from `git diff` or `git log -p`) with `git apply` (even outside the working tree of a repository), or if you have full “patches” from `git format-patch`, you can use `git am` to (re)create the represented commits. – Chris Johnsen May 06 '11 at 02:52