I'm selectively committing parts of a large file and I'd like to see more context around each hunk. Is this possible?
4 Answers
Short answer: no.
git diff
has the -U<n>
option which allows you to customize the number of lines to show around a change. For example, git diff -U5 ...
will show 5 lines of context. As far as I can tell, there is no such option available for the diff display in the interactive mode.

- 138,522
- 17
- 304
- 385
-
7Is there a `-U
` option to show the whole file? (Or is a large number "good enough"?) – titaniumdecoy Mar 21 '12 at 00:51 -
2I'd like to mention that the number in `git diff -U
` is used on both sides of each changed line. So if you have one line changed, `git diff -U5` will show you 11 lines (assuming the one line isn't at the start of end of the file.) – ArtOfWarfare Oct 17 '13 at 12:46 -
6This is for `git diff` not for `git add --patch` or `git add --interactive` – 0xcaff Jun 08 '14 at 23:33
-
1@titaniumdecoy, I posted that as a separate question http://stackoverflow.com/questions/28727424/for-git-diff-is-there-a-uinfinity-option-to-show-the-whole-file – Aleksandr Levchuk Feb 25 '15 at 19:01
-
3Still no solution? – Vitaly Zdanevich Oct 10 '18 at 08:21
This is possible using the GIT_DIFF_OPTS environment variable.
For example:
GIT_DIFF_OPTS=-u10 git add -p
will display 10 lines of context.
See https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_diffing_and_merging .

- 81
- 1
- 1
To confirm, this is still not possible in 2019.
An external tool like jjlee/git-meld-index
can help:
git-meld-index
runsmeld
-- or any other git difftool (kdiff3
,diffuse
, etc.) -- to allow you to interactively stage changes to the git index (also known as the git staging area).
This is similar to the functionality of git add -p
, and git add --interactive
.
In some cases meld is easier / quicker to use than
git add -p
or the staging feature in tools likegit gui
.
That's because meld allows you, for example, to:
- see more context,
- see intra-line diffs
- edit by hand and see 'live' diff updates (updated after every keypress)
- navigate to a change without saying '
n
' to every change you want to skip

- 1,262,500
- 529
- 4,410
- 5,250
I just want to add that you can get the diff with full context using a solution like this https://stackoverflow.com/a/40683517/15410684 by Ezra.
git diff -U$(wc -l MYFILE)
gets you pretty close

- 11
- 2