在 Netbeans 中配置 git

Configuring git in Netbeans

我在 Windows 上使用 Netbeans IDE 开展一个小组 Java 项目,而其他一些人使用 Linux。这会产生与不同行尾字符的冲突,显然可以使用 "git config core.autocrlf true" 来解决。但是,通过 cmd returns:

执行此操作

"'git' 不是内部或外部命令,也不是可运行的程序或批处理文件。"

这是因为 git 集成在 Netbeans 中,因此不能独立安装(和配置)。

如何在 Netbeans 中进行这一配置?谷歌搜索仅 returns 在 Netbeans 中安装 git,而不是其设置。

Netbeans 版本为 11.3。

首先,最好为 Windows 实例单独设置一个 Git 来实现这种设置:您不会依赖 NetBeans 的部分 Git 配置支持那样。
只需将 latest release (like PortableGit-2.27.0-rc1-64-bit.7z.exe) 解压到任何你想要的地方。

其次,core.autocrlf一般为:

  • 最好在全球范围内设置
  • 设置为 false 以便 Git 到 不会 自动更改 EOL

即:

git config --global core.autocrlf false

第三,eol 指令最好在 .gitattributes 文件中指定,该文件是代码库的一部分(因此任何在您的存储库上工作的人都会自动应用)。
参见例如“What's the best CRLF (carriage return, line feed) handling strategy with Git?”。
例如:

*.bat           text eol=crlf # Treat as text. Checkout and add with eol=crlf

然后在新文件夹中再次克隆存储库后切换回 Netbeans,以检查这些指令是否正确应用。