linux (wsl) 和 windows 之间的 Git pathspecs 行为差异

时间:2021-05-12 21:49:26

标签: linux windows git command-line-interface

我不明白为什么相同的命令适用于 linux 而不适用于 Windows。是 pathspecs 语法不同还是 git windows 版本有问题?

在 Windows 上(git 版本 2.31.1.windows.1)

git status -- 'src/test.js'
On branch master
nothing to commit, working tree clean

在 linux 上(wsl:git 版本 2.25.1)

git status -- 'src/test.js'
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/test.js

经典的 git status 在 linux 和 windows 之间给出相同的结果。

1 个答案:

答案 0 :(得分:2)

正如您在 Git 邮件列表中看到的,这实际上是一个 cmd.exe 问题:正在运行:

git status -- 'src/test.js'

传递文字字符串:

'src/test.js'

到 Git,而不是传递:

src/test.js

到 Git。因此,Git 正在寻找文件名包括引号。 (最简单的解决方案是省略引号,这两个系统都不需要此路径规范:对于任何 shell 或 CLI 都没有任何特殊字符。)