Created
October 14, 2013 10:15
-
-
Save daragh/6973630 to your computer and use it in GitHub Desktop.
A shell function to remove trailing whitespace from changed lines in a git commit. Intended to be used as part of a git pre-commit hook.
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
remove_trailing_whitespace_from_changed_lines() { | |
patch=$(mktemp --tmpdir remove-trailing-whitespace-patch-XXXXX) | |
git diff --cached --no-color --diff-filter=M > "$patch" | |
git apply --index --reverse "$patch" | |
git apply --index --whitespace=fix "$patch" | |
rm "$patch" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment