Git tool to remove lines from staging if they consist only of changes in whitespace

前端 未结 3 1781
感情败类
感情败类 2021-02-05 22:28

The point in removing trailing whitespace is that if everyone does it always then you end up with a diff that is minimal, ie. it consists only of code changes and not whitespace

3条回答
  •  粉色の甜心
    2021-02-05 23:27

    My solution on git 1.7.2.5 was as follows (starting without any changes staged):

    git diff -w > temp.patch
    git stash
    git apply --ignore-space-change --ignore-whitespace temp.patch
    # tidy up:
    rm temp.patch
    git stash drop
    

    This leaves your repo back in the starting state with any whitespace only changes removed.

    You can then stage your changes as usual.

提交回复
热议问题