How to get git diff with full context?

How to create a patch suitable for viewing in a crucible?

git diff branch master --no-prefix > patch 

This generates only 3 lines of context. Therefore i do the following

 git diff --unified=2000 branch master --no-prefix > patch 

We hope that all files will have less than 2000 lines. Is there a way to tell git to include all lines in the file for the patch without specifying maximum lines?

+65
git diff code-review atlassian-crucible
Nov 29
source share
4 answers

I know this is old, but I also don't like hard-coded solutions, so I tested this:

 git diff -U$(wc -l MYFILE) 

Using -U seems to be the only way to get closer to the problem, but using promises line counting, that it will work even for a small change in a very large file.

+13
Nov 18 '16 at 18:11
source share
β€” -

It seems very nice:

 git diff --no-prefix -U1000 

With a reservation:

The -U flag indicates context lines. You may need to increase this if there are more than 1000 lines between your changes.

+58
Jul 24 '14 at 11:07
source share

Note: git1.8.1rc1 announcement (December 8, 2012) includes:

The new diff.context configuration can be used to provide the default number of context lines in the output patch to override the hard-coded default three lines.

to help here create a more complete context.

+7
Dec 10
source share

This worked for me on Mac OS:

 git diff -U$(wc -l main.htm | xargs) 

see How to trim spaces from a Bash variable?

+1
Jan 02 '17 at 12:36 on
source share



All Articles