Git 提交删除换行符

Git commit removes line breaks

您好,我在使用 git 源代码管理 (2.19.1.windows.1) 在 VSCode (1.30.1) 中提交文件时遇到问题。 commit改了一个文件,我没改也不想改。设置如下:我在 Windows 10,git 配置为 "checkout windows style, commit unix style" git config --global core.autocrlf true。但是当我提交时会发生以下情况。

这是一个 .json 文件,其中包含以下键:

{
  "description":
    "xxxxxxx"
},

但是我的提交将这一行变成了

{
  "description": "xxxxxxx"
},

已测试 core.autocrlf inputfalse。但这并不能解决这个问题。以前没有遇到过这种行为。还有其他建议或想法吗?谢谢和干杯。


更新: 另一个例子

正在创建一个包含

的test.json文件
{
  "test1": {},
  "test2": {}
}

完美运行,但添加了一个新行,如

{
  "test1": {
  },
  "test2": {}
}

提交后看起来像第一个。这在某种程度上似乎是一个样式问题,不取决于编辑器或系统,因为其他存储库按预期工作。

它应该适用于 git config --global core.autocrlf false

或者你可以试试

.gitattributes 文件。您可以将其用作存储库的模板:

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

问题与 lint-staged 库以及 precommit 挂钩有关 package.json

{
  "scripts": {
    "precommit": "lint-staged"
  }
}

它在提交前根据给定的 linting 规则格式化代码。如果您想了解更多详细信息,请查看正在使用它的 @ngrx/platform library