Remove Whitespace From Staged Files in Git
The following alias lets you remove any whitespace from files that have been added to your index (staged):
wsf = !git commit -mTemp && git stash && git rebase HEAD~ --whitespace=fix && git reset --soft HEAD~ && git stash pop
To explain what is going on here:
- Commit your currently staged files
- Stash any uncommitted changes
- Rebase your last commit (from step 1) and remove any whitespace changes.
- Reset back to your previous commit, but keep changes in the index.
- Pop your previously uncommitted changes back off the stash.
Written by Chris Missal
Related protips
3 Responses
Just don't put whitespaces in your code :D
over 1 year ago
·
Use good IDE it will clean it for you every time you save a file
over 1 year ago
·
Use "git commit --no-verify -mTemp" if you have a pre-commit whitespace enforcement policy.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#