From 8e4004db85d0eeed41e5f68eaa9890b63d2478c7 Mon Sep 17 00:00:00 2001 From: laoyang Date: Tue, 22 Sep 2026 22:05:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E5=AE=9A=E4=BB=93=E5=BA=93=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E7=AC=A6=E4=B8=BA=20LF=EF=BC=8C=E9=81=BF=E5=85=8D=20g?= =?UTF-8?q?it=20archive=20=E4=BA=A7=E5=87=BA=20CRLF=20=E9=80=A0=E6=88=90?= =?UTF-8?q?=E6=AF=94=E5=AF=B9=E5=81=87=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仓库里的 blob 和线上部署的文件都是 LF,但本机 core.autocrlf=true 时 `git archive HEAD` 会把它转成 CRLF 输出。于是拿 git archive 打部署包、 或做改动前后快照比对时,会出现「所有文件都不同」的假象,白排查很久。 加 .gitattributes 锁成 LF 之后,仓库 / 检出 / archive 三者一致。 排查提示:判断行尾不要用 grep 去匹配 $'\r'(Git Bash 下这个转义会被吞成 空模式,导致每一行都命中,得出「全是 CRLF」的错误结论),要用 Python 读字节数统计 CR(b.count(13))。 --- .gitattributes | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..54b5f37 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# 仓库内一律以 LF 存储、以 LF 检出。 +# +# 为什么必须锁死:线上(Linux)文件是 LF,仓库里存的也是 LF,但只要 +# core.autocrlf=true,`git archive HEAD` 就会把内容转成 CRLF 输出。 +# 于是「用 git archive 打的部署包 / 改动前后快照」与工作树逐字节不一致, +# 表现为「所有文件都不同」的假象,白排查半天。锁成 LF 后三者一致。 +# +# 注意:判断行尾别用 `grep -c $'\r'`(Git Bash 下 $'\r' 会被吞成空模式, +# 每行都命中 → 误判「全是 CRLF」)。用 Python 数字节:b.count(13)。 +* text=auto eol=lf