git diff
has the -U
/ --unified
option that
Generate diffs with <n> lines of context instead of the usual three
Questions regarding this option have been asked multiple times:
- Git: show more context when using git add -i or git add -e?
- change no of lines after and before in git diff output
- Can I show more context in a Github diff?
- How can I get "git show" to show diffs with full context?
However, none of those questions, nor the man page, mention any way of changing the context depending on the direction.
For example, grep has the following 'context control options':
After: -A NUM --after-context=NUM
Before: -B NUM --before-context=NUM
Around: -C NUM --context=NUM
So I can use seq 1 10 | grep 5 -A0 -B10
to only get the context above the matching line, in this example it will output row 1 - 5
Question:
How can I extend my git diff
command to only show the <n> lines above the diff?