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?

  • How to mirror Github and VS Online?
  • Publishing private code to OpenShift
  • Update a local branch with the changes from a tracked remote branch
  • Finding a branch point with Git?
  • git-core has been made obsolete by the port git
  • git submodule svn external
  • Why do I have to resolve the same conflict over and over?
  • Ruby on rails Xero integration with Xeroizer
  • How do I get git to stop changing newlines in my files?
  • What are the differences between these git diff commands?
  • Automatically run Git hook when creating a Git tag
  • Pushing a commit in git when local repo has not already merged origin HEAD
  • 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.