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.

  • Merge remote changes into a branch that is not the current branch
  • Best practices for using Git with Magento?
  • VS 2017 - Git failed with a fatal error
  • Is it suggested to have Git repository names in upper or camel case instead of lower case?
  • Selective git ignore by remote?
  • Error in npm install command
  • 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?)

  • Set up a homebrew tap with a git repository on a private network
  • Using git for distribution with autotools
  • Why do files in the working directory get the modified status on switching between Git branches?
  • How to weed out case-sensitivity issues in git on OS X?
  • How are version control histories stored and calculated?
  • How do you preserve code that DIDN'T work?
  • One Solution collect form web for “Git unstage lines where the only changes is white-space?”

     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 .

    Git Baby is a git and github fan, let's start git clone.