我有一個簽入的檔案,CRLF如下CRLF所示git ls-files --eol:
i/crlf w/crlf attr/text eol=crlf src/Project.Tests/ReadTestsV4.cs
但它仍然顯示檔案更改的差異,據說是這樣的(真正的檔案是CRLF):
diff --git a/src/Project.Tests/ReadTestsV4.cs b/src/Project.Tests/ReadTestsV4.cs
index 9f139a6..23d11a5 100644
--- a/src/Project.Tests/ReadTestsV4.cs
b/src/Project.Tests/ReadTestsV4.cs
@@ -1,605 1,605 @@
-^M
-using Renci.SshNet;^M
-using Xunit;^M
-using Project;^M
-using System.Linq;^M
-using System.Diagnostics.CodeAnalysis;^M
-using Microsoft.Extensions.Logging;^M
...
using Renci.SshNet;
using Xunit;
using Project;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
該專案的 gitattributes 是:
*.json eol=lf
*.cs eol=lf
*.csproj eol=lf
*.scss eol=lf
*.ts eol=lf
*.js eol=lf
*.yml eol=lf
*.md eol=lf
*.xml eol=lf
*.html eol=lf
*.config eol=lf
*.txt eol=lf
*.png binary
*.zip binary
# Except for Testing the SSH Libaray CRLF line endings are required for the tests to succeed
src/Project.Tests/**/*.cs eol=crlf
*.bat eol=crlf
我個人的 git 設定是:
[alias]
c = commit -m
aa = add --all
s = status
slog = log -n 10 --date-order --abbrev-commit --graph --pretty=format:"%h|%an|%ar|%s"
glog = log --graph --pretty=oneline --abbrev-commit --decorate --branches --all
[user]
name = Daniel Habenicht
[core]
autocrlf = false
editor = \"C:\\MyPath\\bin\\code.cmd\" --wait
[commit]
gpgsign = true
[gpg]
program = C:\\Program Files (x86)\\GnuPG\\bin\\gpg.exe
我已經嘗試過:
git rm --cached -r .
git reset --hard
但它總是顯示這些變化。
評論:
Project是我縮寫的真實專案名稱的替代品。
uj5u.com熱心網友回復:
這里發生的事情是這樣的:
- 提交的檔案(不能更改)實際上有 CRLF 結尾。
- 索引副本,一??旦你運行
git add,將不會有 CRLF 結尾:它將只有 LF 結尾。(它目前有 CRLF 結尾,基于git ls-files --eol輸出,這是有意義的,因為初始索引副本是通過將提交的副本讀入索引來制作的。這使提交的副本的 CRLF 結尾保持不變。但是eol=crlf說.gitattributes當你運行時git add,Git 應該去掉回車,所以它會這樣做。) - 將來的提交將根據索引中的(將來)進行:也就是說,如果您運行
git add. git add因此,現在提交的內容與運行and之后接下來提交的內容之間的差異涉及從運行后將要編輯git commit的檔案中洗掉所有回車符。git addgit add
基本上,每當您更改某些檔案的“規范化”程序時——Git 將把該檔案或那些檔案從提交的副本轉換為作業樹副本的方式,反之亦然——您可能需要創建一個新的“轉換檔案”首先提交。這樣你就可以使新的規范化生效。然后您可以按照通常的方式進行更改,這些更改將按照新常態進行標準化。
要制作這些新規范化的副本,請考慮使用git add --renormalize,如果您的 Git 不是太古老(非常舊的 Git 版本缺少該--renormalize選項,您必須欺騙這樣的 Git 重新添加檔案)。在進行任何其他更改之前執行此操作,并進行新的提交,該提交的提交訊息將提醒您為什么進行此提交。例如:
renormalize files
We changed the `.gitattributes` setting, so we now need to
renormalize files. Git will show every line changed in
this commit, and `git blame` will point to this commit; use
Git's facilities for skipping over this commit when using
`git blame` because although every line *is* changed, these
changes are purely white-space housekeeping changes that are
not otherwise noteworthy.
現在您已經做出了這個新的提交,以便提交的檔案與新的 normal匹配,您可以像往常一樣恢復作業。如果您稍后正在尋找感興趣的東西并運行git blame并發現此提交及其錯誤訊息,它會提醒您查找git blame檔案并了解如何告訴git blame 不要計算重整化提交。(請參閱--ginore-rev和--ignore-revs-file選項。)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/460224.html
