[英]With Git, how do I turn off the “LF will be replaced by CRLF” warning
使用 Git 時,使用autocrlf = true
標志時,在更改行尾時仍會發出警告。
我了解警告的用途,以及如何關閉行尾標志,但如何關閉警告本身?
您可以關閉警告
git config --global core.safecrlf false
(這只會關閉警告,而不是 function 本身。)
您應該使用core.autocrlf input
和core.eol input
。 或者只是不要讓 git 用autocrlf false
改變行尾,並用core.whitespace cr-at-eol
擺脫差異中 crlfs 的突出顯示等。
希望這可以幫助
我用這種方式:
將您當前的文件保存在 Git 中,這樣您的工作就不會丟失。
git add. -u git commit -m "Saving files before refreshing line endings"
從 Git 的索引中刪除所有文件。
git rm --cached -r.
重寫 Git 索引以獲取所有新行結尾。
git reset --hard
重新添加所有更改的文件,並為提交做好准備。 這是您檢查哪些文件(如果有)未更改的機會。
git add. # It is perfectly safe to see a lot of messages here that read # "warning: CRLF will be replaced by LF in file."
將更改提交到您的存儲庫。
git commit -m "Normalize all the line endings"
有趣的是,我已經應用了這里解釋的兩個配置,並且 my.gitconfig 文件包含以下兩行:
[core]
autocrlf = false
whitespace = cr-at-eol
然而我得到了警告。 現在只是為了嘗試,我注釋掉了這兩行,警告實際上消失了。 不知道為什么我把它們放在首位......
設置“core.safecrlf false”有效。 但是,在我將值更改為“真”后,output 從“警告”變為“致命”,如下所示。
$ git add -A
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory
$ git config --global core.safecrlf false
$ git reset
$ git config --global core.safecrlf true
$ git add -A
fatal: LF would be replaced by CRLF in .gitignore
$
您正在尋找core.whitespace
選項(有關詳細信息,請參閱git config --help
)。
您可以像這樣設置此選項:
$ git config core.whitespace cr-at-eol
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.