【发布时间】:2019-02-08 12:20:12
【问题描述】:
我对在新的 git 克隆后被视为已修改的文件有疑问。
- 所有文本文件都应该有
eol=LF,除了*.txt文件应该有eol=CRLF。
.gitattributes 的外观如下:
* text=auto
*.txt text eol=crlf
*.png binary
*.jpg binary
*.bmp binary
这是我的测试:
- 带有 2 个 .txt 文件(LF.txt 和 CRLF.txt)的新仓库
-
LF.txt: eol=LF(整个文件的行尾是LF) -
CRLF.txt: eol=CRLF(整个文件中的行尾是CRLF)
-
- 添加、提交、推送
- 添加
.gitattributes(包含上述内容):git add .gitattributes,提交,推送 - 回购的新克隆
-
LF.txt:eol 现在是CRLF(如预期的那样) -
CRLF.txt被视为已修改,即使它仍然有CRLF作为 eol
-
- 带有 2 个 .txt 文件(LF.txt 和 CRLF.txt)的新仓库
-
LF.txt: eol=LF -
CRLF.txt: eol=CRLF
-
- 添加、提交、推送
- 添加
.gitattributes(内容如上):git add --renormalize .-
CRLF.txt被视为已修改和暂存(但没有内容差异,eol 仍为CRLF) -
.gitattributes仍未被追踪
-
- 跟踪
.gitattributes:git add . - 提交并推送
- 回购的新克隆
-
LF.txt:eol 现在是CRLF(如预期的那样) -
CRLF.txt: eol 是CRLF(和开头一样) - repo 是干净的
-
附加信息
- 操作系统:Windows 10
- git版本:2.20.1.windows.1
问题
- 测试 1:为什么 CRLF.txt 在新克隆后被视为已修改?
- 测试 2:
git add --renormalize .实际上在做什么?为什么.gitattributes也不上台? - 在已经有一些历史记录的 repo 中设置
.gitattributes时,是否建议运行git add --renormalize以避免在新克隆后修改文件?
【问题讨论】:
标签: git eol gitattributes