Taking corrective action with git pre-commit
eng.wealthfront.com
eng.wealthfront.com
Worse than not fixing trailing whitespace (or only fixing it in the lines you are actually changing) is fixing whitespace AND changing the code in the same commit.
Doing something like what's proposed in the article is acceptable as long as you do even more shell magic so it only works on lines actually touched by the commit.
Same goes for scripts running on the server (just doing validation there of course!). You can only act on lines actually changed by the commit if you're dealing with repositories imported from pre-git days, or you will be seriously hated by your teammates :-)
Personally, I prefer to just rewrite the whole tree in one go, but that scares a lot of people. So just commit the fix and it will all work out in the end.