Skip to content

Instantly share code, notes, and snippets.

@raine
Last active December 17, 2015 01:19
Show Gist options
  • Select an option

  • Save raine/5527403 to your computer and use it in GitHub Desktop.

Select an option

Save raine/5527403 to your computer and use it in GitHub Desktop.
Remove whitespace from git diffs
#!/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