4

I want to remove trailing whitespace from my modifications to files.

However, this is different than this or this because I want to do it whenever, without committing.

For example,

  1. Remove trailing whitespace.
  2. git diff
  3. Review code with another programmer.
  4. git commit

But I don't want to remove trailing whitespace from lines I didn't modify, so this won't work for me either.

Community
  • 1
  • 1
Paul Draper
  • 78,542
  • 46
  • 206
  • 285
  • See http://stackoverflow.com/a/15398512/1256452 (note: I have not tried this myself, but it looks like exactly what you want). – torek Dec 13 '13 at 17:58
  • 1
    Some editors can do it upon Save. Eclipse does it happily and has a setting of "only in changed lines". If not - bash script is your choice. Git diff will display the changed lines and sed will remove the trailing whitespace. – LiMar Dec 13 '13 at 18:01

0 Answers0