I have a source code file that for some reason have ended up with mixed indentation (spaces and tabs used for indentation).
I have made quite a few changes and now I wish to commit those changes in git. Unfortunately I by accident instructed my editor to fix all indentation. So now it looks like I have modified a lot of lines, where the only change is changes to white-space.
My commit has to be reviewed by my colleagues in Gerrit, so having a lot of white-space-only changed lines show up as changes adds a lot of noise.
How can I unstage all lines in a file, where the only change is to white-space (or indentation), such that my git commit only contains actually changed lines?
(Or alternatively, how can I only stage the lines of a file where more than white-space is changed?)
git diff -w --no-color [file names] | git apply --cached --ignore-whitespace
Basically it applies the patch which would be applied with add without whitespace changes. You will notice that after that there will still be unstaged changes, it's the whitespaces left, to checkout them run: git checkout .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With