现象:文件内容一个字没改,git diff 却显示整行整行地变。 根因是同一份文件在 Windows 和 WSL 之间来回编辑,被存成了 CRLF 和 LF 两种版本,diff 里全是假改动,review 时看不出真正改了什么。 配置说明 - 默认文本文件在仓库里统一存 LF - .bat / .cmd / .ps1 保持 CRLF,否则 Windows 下可能执行异常 - .xlsx / .png / .exe / .db 等标记为 binary,绝不做换行符转换, 否则文件会损坏 注意:本次只加配置,没有对已有文件做规范化。 需要在工作区干净时另外跑一次 git add --renormalize . Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
45 lines
1.2 KiB
Plaintext
45 lines
1.2 KiB
Plaintext
# 统一换行符,避免 Windows 和 WSL 之间来回切导致的假改动。
|
|
#
|
|
# 现象:文件内容一个字没改,git diff 却显示整行整行地变,
|
|
# review 时看不出真正改了什么。根因是同一个文件在两个环境里
|
|
# 被存成了 CRLF 和 LF 两种版本。
|
|
#
|
|
# 配置生效后需要在**干净的工作区**上跑一次:
|
|
# git add --renormalize .
|
|
# git commit -m "chore: 统一换行符"
|
|
# 干净的意思是先把手上没提交的改动提交掉,否则会和真实改动混在一起。
|
|
|
|
# 默认:由 git 自动判断是不是文本;是文本就在仓库里统一存成 LF
|
|
* text=auto eol=lf
|
|
|
|
# 这两类是 Windows 脚本,必须 CRLF,否则可能执行异常
|
|
*.bat text eol=crlf
|
|
*.cmd text eol=crlf
|
|
*.ps1 text eol=crlf
|
|
|
|
# 源码和文档,明确按 LF
|
|
*.py text eol=lf
|
|
*.go text eol=lf
|
|
*.md text eol=lf
|
|
*.txt text eol=lf
|
|
*.mod text eol=lf
|
|
*.sum text eol=lf
|
|
*.html text eol=lf
|
|
*.css text eol=lf
|
|
*.js text eol=lf
|
|
*.sql text eol=lf
|
|
|
|
# 安卓控件树导出,是文本
|
|
*.xml text eol=lf
|
|
|
|
# 二进制:绝不能做换行符转换,否则文件会损坏
|
|
*.xlsx binary
|
|
*.xls binary
|
|
*.png binary
|
|
*.jpg binary
|
|
*.jpeg binary
|
|
*.gif binary
|
|
*.ico binary
|
|
*.exe binary
|
|
*.db binary
|