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

 

posted @   邢韬  阅读(233)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示