Skip to content

Instantly share code, notes, and snippets.

@atfornes
Created September 5, 2017 11:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atfornes/f4a917c6c0cf5b773824a6545ae2ef5e to your computer and use it in GitHub Desktop.
Save atfornes/f4a917c6c0cf5b773824a6545ae2ef5e to your computer and use it in GitHub Desktop.
Git rebase interactive cleaning space only line changes
#!/bin/bash
## Rebases interactive current branch over master (or <branch> provided as first argument) removing whitespace changes
# based on https://stackoverflow.com/a/9784089/4928558 and https://stackoverflow.com/a/23911001/4928558
branch=master
if [[ $1 ]];
then
branch=$1;
fi
git rebase -i -Xignore-all-space $branch -x "git diff --binary HEAD^ -U0 -w --no-color > patch && git checkout HEAD^ -- . && git apply patch --ignore-whitespace --unidiff-zero && git add -u && git commit --amend --no-edit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment