_ppnlg
Last Updated: February 25, 2016
·
3.413K
· ChrisMissal
3c4478e6ae6c60b73d21c9fa0d1785ea

Remove Whitespace From Staged Files in Git

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:

  1. Commit your currently staged files
  2. Stash any uncommitted changes
  3. Rebase your last commit (from step 1) and remove any whitespace changes.
  4. Reset back to your previous commit, but keep changes in the index.
  5. Pop your previously uncommitted changes back off the stash.

Source: http://stackoverflow.com/questions/19151940/git-remove-trailing-whitespace-in-new-files-before-commit#comment28450261_19156679

Say Thanks
Respond

3 Responses
Add your response

11512
5736f5a1c2a22df69e7d6e0da0fca6d2

Just don't put whitespaces in your code :D

over 1 year ago ·
12032
D8d7ce2f807101bb328b50be18f4e912

Use good IDE it will clean it for you every time you save a file

over 1 year ago ·
22138
None

Use "git commit --no-verify -mTemp" if you have a pre-commit whitespace enforcement policy.

over 1 year ago ·
Filed Under