I don’t see a difference between the output of ‘git format-patch’ and ‘git diff’, is there any? And won’t I be able to use ‘git diff’ to produce a patch and then apply it using git apply?
My problem is that I have changes added to the index, but apparently git format-patch only accepts commits, so if I can use the output of diff, then I can use this command to produce a patch for the changes in the index:
git diff --cached > index.patch
A patch created with
git format-patchwill also include some meta-information about the commit (committer, date, commit message, …) and will contains diff of binary data. Everything will be formatted as a mail, so that it can be easily sent. The person that receive it can then recreate the corresponding commit withgit amand all meta-data will be intact. It can also be applied withgit applyas it is a super-set of a simple diff.A patch crated with
git diffwill be a simple diff with context (thinkdiff -u). It can also be applied withgit applybut the meta-data will not be recreated (as they are not present).In summary,
git format-patchis useful to transmit a commit, whilegit diffis useful to get a diff between two trees.