git ^M问题
问题描述
ts编译后git出现大片标红修改,但实际我只修改了一个文件,其他的只是重新编译而已,并未做出修改,为什么会出现这种情况呢?
解决
首先我们diff一下看看区别
可以看到,区别是一个^M的结束符
经查阅后发现,git有配置说明
https://docs.github.com/cn/get-started/getting-started-with-git/configuring-git-to-handle-line-endings
于是在根目录下创建了一个.gitattributes配置文件成功解决
# Set the default behavior, in case people don't have core.autocrlf set. * text=auto # Explicitly declare text files you want to always be normalized and converted # to native line endings on checkout. *.c text *.h text # Declare files that will always have CRLF line endings on checkout. *.sln text eol=crlf *.css text eol=crlf *.js text eol=crlf *.md text eol=crlf *.txt text eol=crlf *.sql text eol=crlf *.php text eol=crlf *.ts text eol=crlf # Denote all files that are truly binary and should not be modified. *.png binary *.jpg binary
后续若在git add时出现,fatal: LF would be replaced by CRLF
可在.git文件夹下打开config配置文件,添加上下面两句话:
autocrlf = false safecrlf = false
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器