【问题标题】:git bash on windows vs. WSLWindows 上的 git bash 与 WSL
【发布时间】:2019-03-25 03:23:32
【问题描述】:

我在我的 Windows 上下载了 git,并且出现了一些其他的东西,包括 git bash。

虽然我不知道为什么 bash 终端被包含在“git”中, 它不仅支持 git 的功能,还支持 mkdir、cp、mv 等其他功能,就像真正的 linux bash 终端一样。

最近我了解了 WSL(Linux 的 Windows 子系统),它使 bash 终端在 windows 中可用。

git bash 在功能方面是否比 WSL 差很多?

它是否包含一些 WSL 没有的约束?

【问题讨论】:

  • 确切的问题出现在谷歌quora.com/…
  • 我也在win10上同时使用,我的经验是wsys提供了linux系统可以提供的全套工具链(例如c++编译器,apt-get),而git bash是一个终端模拟器。

标签: git-bash windows-subsystem-for-linux


【解决方案1】:

Git for Windows 正在使用mingw-w64 项目(如illustrated here)和msys2
在“How are msys, msys2, and msysgit related to each other?”中查看更多信息。

这与模拟实际 Linux 发行版的 WSL 大不相同。

它是否包含一些 WSL 没有的约束?

Windows 版 Git 基于 POSIX 兼容层 which has limitations: POSIX support is deprecated since Windows 8


注意:WSL 将很快成为 replaced by WSL2,它使用一个全新的架构,该架构使用 real Linux kernel


如果您的程序依赖于 Git bash(而不是 WSL/WSL2 bash),请确保将所述适用于 Windows 的 Git 放在 your PATH 中,如“USING “GIT BASH” FROM APPVEYOR”中所述的 Jon Skeet 和 @987654334 中所述@。

# Make sure we get the bash that comes with git, not WSL bash
  - ps: $env:Path = "C:\Program Files\Git\bin;$env:Path"

【讨论】:

  • WSL2中安装的git bash和git可以共存吗?我认为应该是;然而,当我在 WSL2 中运行 git status 时,在我之前通过 git bash 处理过的存储库中,它会执行“刷新索引”并将所有文件显示为已修改。但是,来自 WSL2 的 git log 确实显示了正确的日志。
  • @dqbydt 你的 WSL 会话中有什么 git 版本?
  • WSL (Debian) git 版本:2.20.1; git bash git 版本:2.34.1.windows.1
  • @dqbydt 首先在 Debian 上尝试 git config --global core.autocrlf false,然后是 git add --renormalize .
  • 这显示为“要提交的更改”所有之前显示为“未暂存”的文件。
【解决方案2】:

在 Windows 工具中更改文件时,WSL 不会触发文件处理程序 - https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

因此,您不能在 WSL 中运行开发服务器,因为在 Windows 编辑器中所做的代码更改不会反映在开发服务器中。

【讨论】:

猜你喜欢
  • 2021-02-22
  • 2018-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-10
相关资源
最近更新 更多