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 @ 2022-03-30 15:13  邢韬  阅读(217)  评论(0编辑  收藏  举报