Git diff to show only lines that have been modified

diff()git

When I do a git diff, it shows lines that have been added:

+ this line is added

lines that have been removed:

- this line is removed

but it also shows many lines which are not modified:

this line is not modified
this line is also not modified

This results in the actual git diff looking something like this:

+ this line is added
  this line is not modified
- this line is removed
  this line is not modified

Can I ask git to show only lines that have been modified and ignore all other code which has not been modified? I have written a method which will remove all the lines which don't have a "+" or "-" sign in front of them, but I am sure there must be a simpler way to do this.

In my git diff, I am only interested in seeing the lines that have been modified.

Best Answer

What you want is a diff with 0 lines of context. You can generate this with:

git diff --unified=0

or

git diff -U0

You can also set this as a config option for that repository:

git config diff.context 0

To have it set globally, for any repository:

 git config --global diff.context 0