Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git unstage lines where the only changes is white-space?

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?)

like image 966
Bjarke Freund-Hansen Avatar asked May 28 '14 11:05

Bjarke Freund-Hansen


1 Answers

 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 .

like image 149
griffon vulture Avatar answered Oct 13 '22 02:10

griffon vulture