git - core.eol = crlf 在添加时而不是在结帐时设置 crlfs
问题描述
根据有关文件core-eol
为标记为文本的文件设置要在工作目录中使用的行结束类型(通过设置 text 属性,或者通过设置 text=auto 和 Git 将内容自动检测为文本)。
所以问题 #1 是:core-eol 是否可以在没有 .gitattributes 文件的情况下工作?
问题 #2 是用于签出到工作目录还是从工作目录签入到索引?或两者?
使用 git for windows 2.33.1 和全局设置(无本地)core.autocrlf = false
(因此它不会覆盖 core.eol)core.eol = crlf
并运行 Git Bash(回显命令 > 导致 eol=LF)
1. git config --global core.autocrlf false
2. git config --global core.eol crlf
3. mkdir testEOL
4. cd testEOL
5. echo Hello > hello.txt // file has LF eol
6. git init
7. git add . // file still has LF eol in working directory
8. git commit -m "Initial commit"
9. echo "* text" > .gitattributes
10. git add . // file has LF eol, however -> warning: LF will be replaced by CRLF in .gitattributes.
11. git commit -m "Git attributes"
12. echo New Line >> hello.txt
13. git add . // warning: LF will be replaced by CRLF in hello.txt.
14. git commit -m "Change to hello"
14a. git rm hello.txt
15. git reset --hard HEAD // EDIT: hello.txt has CRLF
这些问题的答案似乎是:
- 否(第 7 行)
- 签入和签出(第 10,13 和 15 行)- 删除文件后(见更新的 14a)
这只是我的实验还是这是真的?
解决方案
该文档指出,core.eol
仅影响具有text
属性集的文件。如果未设置该属性,Git 会查看core.autocrlf
以确定它,并设置将覆盖该core.eol
值。因此,如果要控制行尾,则需要使用.gitattributes
文件来设置属性。
core.eol
选项和eol
属性只影响工作树中的内容。任何具有该text
属性的文件在存储在存储库本身时都会将其行尾转换为 LF,然后该属性或设置将确定它在工作树中具有哪些行尾。
您看到的警告是告诉您工作树中的文件具有 LF(因为您使用 Unix shell 工具创建了它),但是您对工作树的设置要求它在工作树中具有 CRLF。因此,您在未来结账时可能会遇到与现在不同的行为。
执行 agit add
不会将工作树中的文件更改为具有指定的结尾,只会将其添加到具有 LF 结尾的存储库中。如果要更改工作树中的行尾,则需要强制再次签出文件,您已经完成了git reset --hard
.
推荐阅读
- php - SQLSTATE [HY093]:无效参数编号错误,即使我使用的是 bindParam 而不是执行
- jakarta-ee - TimerService#createTimer 忽略延迟
- android - 如何在应用加载时显示可变信息
- python - 即使在 git-bash.exe 上运行良好,“conda activate”在 bash.exe 上也会失败
- sql - 通过将表列映射到其他表的列值来重命名表列
- java - 在 fileinputstream 输入中分离文件并将数据插入到 oracle 表中
- marklogic - 从表中提取数据 (MarkLogic)
- angular - 在一个数组中合并/组合/加入两个 Observable 数组,并在 Ionic 3 应用程序中一起使用 ngFor 显示它
- flask - 通过前端将用户指定的本地文件上传到 Google Cloud Storage
- google-sheets - 有没有办法在制作特定例外时计算工作表上的所有单词?