How to create patch suitable for reviewing in crucible?
git diff branch master --no-prefix > patch
This generates only 3 lines of context. S
Note: git1.8.1rc1 announce (December 8th, 2012) includes:
A new configuration variable "
diff.context
" can be used to give the default number of context lines in the patch output, to override the hardcoded default of 3 lines.
so that could help, here, generate a more complete context.
I know this is old, but I also dislike hard-coded solutions, so I tested this:
git diff -U$(wc -l MYFILE)
Using -U seems to be the only way to approach the issue, but using a line count promises that it will work for even a small change in a very large file.
This seems to work pretty nicely:
git diff --no-prefix -U1000
With the caveat:
The
-U
flag specifies lines of context. You might need to increase this if there are more than 1000 lines between your changes.
Got inspiration and so I added a git alias.
$ cat ~/.gitconfig | fgrep diff
df = "!git diff -U$(wc -l \"$1\" | cut -d ' ' -f 1) \"$1\""
$ git df <file>
Update:
Just found "git df" does not work sometimes, due to directory change when executing git alias. (See git aliases operate in the wrong directory). So this is the updated version:
$ cat ~/.gitconfig | fgrep df
df = "! [ \"$GIT_PREFIX\" != \"\" ] && cd \"$GIT_PREFIX\"; ~/bin/git_df.sh"
$
$ cat ~/bin/git_df.sh
#!/bin/bash
for FILE in $@; do
git diff -U$(wc -l "${FILE}" | cut -d ' ' -f 1) "${FILE}"
done
exit 0
Previously accepted solutions don't work for me when viewing a specific file/commit (the -U
option seems to mess with rev/path parsing), but --inter-hunk-context=
works in this case on git version 2.24.0
:
git diff \
--no-prefix \
--inter-hunk-context=2000 \
master -- \
path/to/file.py
If you don't know the file size, you can of course find it with wc -l
instead of hard-coding it:
git diff \
--no-prefix \
--inter-hunk-context=$(wc -l path/to/file.py) \
master -- \
path/to/file.py
This worked for me on macOS:
git diff -U$(wc -l main.htm | xargs)
see "How to trim whitespace from a Bash variable?"