Make Git automatically remove trailing white space before committing

I’m using Git with my team and would like to remove white space changes from my diffs, logs, merges, etc. I’m assuming that the easiest way to do this would be for Git to automatically remove trailing white space (and other white space errors) from all commits as they are applied.

I have tried to add the following to the ~/.gitconfig file, but it doesn’t do anything when I commit. Maybe it’s designed for something different. What’s the solution?

[core]
    whitespace = trailing-space,space-before-tab
[apply]
    whitespace = fix

I’m using Ruby in case anyone has any Ruby specific ideas. Automatic code formatting before committing would be the next step, but that’s a hard problem and is not really causing a big problem.

17 Answers
17

Leave a Comment