Matthew Ha
Matthew Ha

Reputation: 55

git diff shows unnecessary empty lines

I think I messed something up with my git configuration.

When I type commands like git diff or git branch I get output that looks like this:

{many    
empty    
lines}

diff --git a/Camera/aivero_integration/Makefile b/Camera/aivero_integration/Makefile 
. 
. 
. 

(END)

Additionally, the output from the commands don't stay in my terminal after I leave the git diff or git branch. Its almost as if the commands "open" another terminal application.

Upvotes: 0

Views: 295

Answers (1)

Enrique Arevalo
Enrique Arevalo

Reputation: 333

Perhaps there is a better answer, but the best solution I've found so far is this.

First, you must control the definition of "whitespace" that Git is currently using. Create or edit the .gitconfig in your project, to include

[core]

    whitespace = -trailing-space,-indent-with-non-tab,-tab-in-indent
Next, you must control the definition of a word used. Instead of just using git diff -w, add --word-diff-regex=[^[:space:]]:

git diff -w  --word-diff-regex=[^[:space:]]
Y

ou'll still see the context, which (in my case, since I'm trying to ensure that there are no differences except whitespace differences) is not helpful. You can use -U0 to tell Git to give you 0 lines of context, like so,

git diff -w -U0 --word-diff-regex=[^[:space:]]

but you'll still get output that looks pretty much like context, but it's still much better than looking through all the changes carefully and manually to make sure they are only whitespace changes.

Upvotes: 2

Related Questions