By default, git diff only spits out three lines of context above and below your changes. However, it’s possible to include the entire file. Generate a patch of some changes with full context:
git diff --no-prefix -U1000 > /tmp/mydiff.patch
If you’ve already committed your changes, you can use git show with the same syntax:
git show --no-prefix -U1000 > /tmp/mydiff.patch
These are useful for pre-commit code reviews in Crucible. You can just upload the resulting patch file.
The –no-prefix option gets rid of the “/a/” and “/b/” destination prefixes that show up by default.
The -U flag specifies lines of context. You might need to increase this if there are more than 1000 lines between your changes.
If you don’t want to type all that out, add an alias in your ~/.gitconfig file.
[alias] code-review = diff -p --no-prefix -U1000
Then you can just do:
git code-review > /tmp/mydiff.patch