3

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:


However, none of those questions, nor the man page, mention any way of changing the context depending on the direction.

For example, 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?

0stone0
  • 34,288
  • 4
  • 39
  • 64
  • 3
    You might be able to do something with [`git difftool`](https://git-scm.com/docs/git-difftool). Unfortunately, GNU diff doesn't have Before and After context options only, so `git difftool -y -x 'diff -A0 -B10'` won't work. – IMSoP Apr 08 '22 at 14:22

0 Answers0