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.

  • How do I merge a pull request into a feature branch of my github project?
  • git add remote in submodule
  • Git merge reports file deleted when it's not
  • git branch several commits ago?
  • Changed GitHub password, no longer able to push back to the remote
  • Publish Git repository to SVN
  • 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?)

  • Emacs lisp lambda with lexical binding?
  • Using github issues as mylyn task repository?
  • Coalescing adjacent commit and its revert
  • git branch delete - HOOK
  • Programmatically `git checkout .` with dulwich
  • How to access to repository file with GIT in post-receive hook
  • 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.