How can you combine git add patch -p mode with diff's ignore-all-space

前端 未结 4 2119
别跟我提以往
别跟我提以往 2021-01-31 08:36

How can I do git add with patch mode but ignoring whitespace changes.

The use case is for when you\'ve reformatted a file and also made changes to it. I want to commit t

4条回答
  •  孤城傲影
    2021-01-31 09:32

    A more robust and versatile version of @"Justin C"s answer is:

    anw = !git diff -U0 -w --no-color -- \"$@\" | git apply --cached --ignore-whitespace --unidiff-zero "#"
    
    • With no argument - adds all tracked files' non-whitespace changes
    • Given files/directories - only adds non-whitespace changes in those locations

    See this answer for more.

提交回复
热议问题