Skip to content

Instantly share code, notes, and snippets.

@jakl
Last active December 22, 2015 06:09
Show Gist options
  • Save jakl/6428711 to your computer and use it in GitHub Desktop.
Save jakl/6428711 to your computer and use it in GitHub Desktop.
Remove trailing whitespace and convert tabs to 2 spaces
# Warning: Operates on binary files - make sure to have all files in git to revert them!
# remove trailing whitespace recursively in a repo
find . -type f -not -iwholename '*.git*' | xargs sed -i -r 's/[ ]+$//' # [] contains a space and a tab
# convert tabs to spaces:
find . -type f -not -iwholename '*.git*' | xargs sed -i -r 's/ / /g' # s/1/2/g ... 1 is a tab, 2 is two spaces
# revert binary files
git diff | grep Binary | sed 's/^Binary files a\///' | sed 's/ and .*$//' | xargs git checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment