How to control the number of lines that surround each difference when running `git diff`?

Depending on what I am diffing sometimes I want to see several lines (let’s say 10) above and below the +insertions -deletions, sometimes I just want to see a couple of lines surrounding them.

Is there a way to tell git the number of line he should show me?

  • Why vendor folder's size drops from 100MB to 15MB after pushing it to bitbucket git repository?
  • Amend the second to last commit
  • Are git emails of authors in commits publicly readable?
  • partly cherry-picking a commit with git
  • Working tree vs working directory
  • Git pull rebase - What is it rebasing
  • Jenkins hangs at git fetch
  • Sparse Git checkout of files into parent directory
  • How to filter history based on gitignore?
  • How can I find all the merges that had conflicts in a Git repository?
  • git-stash is moving my master branch
  • Why is my git repository so big?
  • 2 Solutions collect form web for “How to control the number of lines that surround each difference when running `git diff`?”

    The option you’re looking for is -U. From the man page:

    -U<n>, --unified=<n>

    Generate diffs with lines of context instead of the usual three. Implies -p.

    git diff -U<num>. Default is 3.

    Git Baby is a git and github fan, let's start git clone.