Brendan Dash

Brendan Dash

將 Windows Git 的行尾設置為 lf

原因#

在撰寫 Debbl/eslint-config 的測試時

await Promise.all(
  files.map(async (file) => {
    let content = await fs.readFile(join(target, file), "utf-8");
    const source = await fs.readFile(join(from, file), "utf-8");

    if (content === source) {
      content = "// 未更改\n";
    }

    await expect.soft(content).toMatchFileSnapshot(join(output, file));
  }),
);

在 github action 中有使用多個系統的測試

strategy:
  matrix:
    node: [lts/*]
    os: [ubuntu-latest, windows-latest, macos-latest]
  fail-fast: false

但是在測試 windows 時總是報錯 test,顯示 input 和 output 不符合,在測試後發現是 windows 預設的在 git 下載時的 eolcrlf

所以搜了一下在 GitHub Action 如何設置 eollf actions/checkout#135

最終添加如下命令 ci.yml

windows 可以通過以下命令設置為 lf

git config --global core.autocrlf false
git config --global core.eol lf
- name: 設置 git 使用 LF
  run: |
    git config --global core.autocrlf false
    git config --global core.eol lf

通過 .gitattributes 設置#

* text=auto eol=lf

引用#

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。