If your changes are not staged
To stage changes that are not just whitespace changes, you can do:
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -
Afterwards, to remove all unstaged changes (those changes that differ only in whitespace), you can do:
git checkout .
If your changes are staged
Unstage your changes by doing a git reset --mixed
and continue from the top of this answer. Note that mixed
is the default mode and can be omitted.