When using git add --patch (or git add -p), Git shows you a hunk (a chunk of changes) and prompts you for action. By default, Git displays a limited amount of context around each hunk, which can make it hard to understand the full picture.
Use the -U (or --unified) option to specify the number of unified context lines Git should show around each change. The default is usually 3 lines. To see more, use:
shgit add -p -U10 # Shows 10 lines of context around each hunk
This applies to the current add -p session.
If you always want more context, configure Git globally or locally:
shgit config --global diff.unified 10 # Sets 10 lines of context for all diffs
or for a specific repo:
shgit config diff.unified 10
This affects git diff, git add -p, and other commands that show diffs.
If the diff is long, use a pager like less for easier navigation:
shGIT_PAGER=less git add -p
or set it in your Git config:
shgit config --global core.pager 'less -r'
If you want to see the full file while editing a hunk, you can:
git diff in another window to see the full diff.If the command line is too limiting, consider using a GUI tool like:
git add -p in Magit (Emacs)These tools often provide a more visual and interactive way to stage hunks with full context.
Tip: If you want to see the full file for a specific hunk, you can also use git difftool with your preferred diff tool (e.g., vimdiff, meld, kdiff3).
Would you like help setting up a specific diff tool or pager?