Skip to content

Instantly share code, notes, and snippets.

@ConradIrwin
Created October 25, 2011 21:37
Show Gist options
  • Select an option

  • Save ConradIrwin/1314394 to your computer and use it in GitHub Desktop.

Select an option

Save ConradIrwin/1314394 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
# Removes whitespace errors (as configued by core.whitespace) from both the working
# tree and the index.
# Goes to some lengths to avoid problems that could be caused by applying two mechanically
# altered patches in sequence.
to_work=`tempfile`
to_index=`tempfile`
# take a diff from HEAD to the working tree.
# full-index seems to be needed sometimes with binary files, TODO figuremeout
git diff HEAD --full-index > $to_work
# take a diff from HEAD to the index.
git diff HEAD --cached --full-index > $to_index
# recreate the working tree without whitespace errors (throws away the index)
git reset HEAD --hard
git apply $to_work --whitespace=fix
# recreate the index without whitespace errors (preserves the working tree)
git reset HEAD --mixed
git apply $to_index --whitespace=fix --cached
rm $to_index $to_head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment