Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 336
nacho4d Avatar asked Nov 10 '11 04:11

nacho4d


People also ask

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

What does git diff -- cached do?

git diff --cached --merge-base A is equivalent to git diff --cached $(git merge-base A HEAD) . This form is to view the changes you have in your working tree relative to the named <commit>. You can use HEAD to compare it with the latest commit, or a branch name to compare with the tip of a different branch.

What does M mean in git diff?

^M represents carriage return. This diff means something removed a Unicode BOM from the beginning of the line and added a CR at the end.


2 Answers

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.

like image 77
Cascabel Avatar answered Sep 21 '22 12:09

Cascabel


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

like image 37
Robert Avatar answered Sep 21 '22 12:09

Robert