Last active
December 17, 2015 01:19
-
-
Save raine/5527403 to your computer and use it in GitHub Desktop.
Remove whitespace from git diffs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # set -x verbose #echo on | |
| # Find files with trailing whitespace | |
| for file in `git diff --check --cached | grep '^[^+-]' | grep -o '^.*[0-9]\+:'` ; do | |
| file_name=`echo ${file} | grep -o '^[^:]\+'` | |
| line_number=`echo ${file} | grep -oP '(?<=:)[0-9]+(?=:)'` | |
| sed -i '' "${line_number}s/[[:space:]]*$//" ${file_name} | |
| git add ${file_name} | |
| done | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment