返回
创建于
状态公开

https://git-scm.com/docs/gitattributes

windows 和 unix 换行不同

修改 Git 全局配置

全局修改 Git 的 core.eolcore.autocrlf 配置正确:

  1. 设置换行符为 LF:

    bash
    1git config --global core.eol lf
  2. 禁用自动换行符转换(推荐):

    bash
    1git config --global core.autocrlf false

使用 .gitattributes 文件

使用 .gitattributes 来解决,下面是一个例子。

js
1# Set the default behavior, in case people don't have core.autocrlf set.
2* text=auto
3
4# Denote all files that are truly binary and should not be modified.
5*.png binary
6*.jpg binary
7*.gif binary
8*.ico binary
9
10# Declare files that will always have LF line endings on checkout.
11*.tsx text eol=lf
12*.ts text eol=lf
13*.mts text eol=lf
14*.cts text eol=lf
15*.js text eol=lf
16*.mjs text eol=lf
17*.cjs text eol=lf
18*.jsx text eol=lf
19*.md text eol=lf
20*.scss text eol=lf
21*.less text eol=lf
22*.css text eol=lf
23*.json text eol=lf
24*.yml text eol=lf
25*.yaml text eol=lf
26*.xml text eol=lf
27*.html text eol=lf
28*.htm text eol=lf
29*.sh text eol=lf
30*.bat text eol=lf
31*.cmd text eol=lf
32*.ps1 text eol=lf