git - trim whitespace

前端 未结 4 735
南方客
南方客 2021-02-02 12:51

I\'ve accidentally put some whitespace in my initial commit - it shows up red in git diff --color. What\'s the best way to get rid of the existing whitespace and ho

4条回答
  •  灰色年华
    2021-02-02 13:16

    To trim trailing whitespace on all files in the current directory, use:

    sed -i 's/[[:space:]]*$//' *
    

    To warn about future whitespace errors (both trailing spaces and spaces before tabs), and to fix whitespace errors in patches, add the following code to your gitconfig file:

    [core]
        whitespace = trailing-space,space-before-tab
    [apply]
        whitespace = fix
    

提交回复
热议问题