git add時候出現錯誤 warning: in the working copy of

git add時候出現錯誤 warning: in the working copy of xxxxxxxxxxxx, CRLF will be replaced by LF the next time Git touches it

這不是錯誤,其實只是個 Git 的警告訊息,意思是:

目前檔案中的行尾是 CRLF(Windows 格式),但 Git 儲存時會把它轉成 LF(Unix 格式)

解決方式(視需求選擇)

選項 1:不理它(最簡單)

這只是警告,照常 add、commit 不會出錯。如果不介意行尾轉換,完全可以忽略它。

選項 2:讓 Git 自動幫你處理行尾

git config --global core.autocrlf true

可以執行下面這行,Git 會幫你把所有行尾重新整理一遍:

git add --renormalize .

然後 commit,Git 就不再囉嗦了。

總結一下應該做的順序:

git config --global core.autocrlf true
git add --renormalize .
git commit -m "Normalize line endings"