Edward Thomson

This is day 17 of my Git Tips and Tricks Advent Calendar. If you want to see the whole list of tips as they're published, see the index.

I hope that I've encouraged you to get your .gitattributes set up correctly so that everybody on your team is committing with the same line ending configuration. But maybe you haven't had time to fix that yet, maybe you're on holiday, or, heck, maybe you don't even care… 🤯

Even if some people on your team are still committing files with CRLF line endings, while others are committing with LF; some tools like GitHub have you covered.

If you see a pull request that appears to change every line (but there are only a few actual content changes) then that's a dead giveaway that somebody's line ending configuration is wrong. Here I've actually made changes only to lines one and three, but the diff makes it look like the whole file is rewritten:

Diff with whitespace changes

That's because the whole file is rewritten. I had Windows style line endings (CRLF) in the repository, but this pull request has rewritten the file with Unix style line endings (LF).

Now, you might not want to take a pull request that rewrites the whole file with new line endings. But in this case, I don't mind. I'm transitioning from having no .gitattributes and living in the wild wild west when it comes to line ending configuration, and I'm moving into the nice orderly world of Unix line endings.

But, what I really want here is to see just what actually changed, and ignore the lines that only had whitespace changes. And GitHub has me covered.

In the Diff Settings options at the top of the pull request diff tab, I can select "Hide whitespace changes".

Hide whitespace changes

When I do, GitHub will only show me the actual, non-whitespace differences in my pull request:

Diff with no whitespace changes

And now I can focus on reviewing what actually changed in the file, instead of the line endings.