Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout (discard changes) on files with only whitespace/lineending changes

Tags:

git

Is there a command/option/filter to discard the changes (via a checkout) on all the modified files whose changes only affect whitespace?

Alternatively, staging only files with non-whitespace changes (including staging their whitespace changes) would be fine.

like image 421
Richard Szalay Avatar asked Apr 17 '14 00:04

Richard Szalay


1 Answers

You could:

  • first apply all non-whitespace changes (see "Git add only non-whitespace changes")

    git diff -w --no-color | git apply --cached --ignore-whitespace
    
  • clean any other changes (see "How do you discard unstaged changes in git?")

    git checkout -- .
    

In this solution, the order is important.

like image 192
VonC Avatar answered Oct 17 '22 21:10

VonC