为什么 ls 在 GitShell 中工作,但 ls -a 或 ls -la 不工作?

Why does ls work in GitShell, but ls -a or ls -la not work?

我开始在我的 Windows 7 计算机上使用 GitShell 以尝试让脚本正常工作。当我在 shell 中键入 ls 时,它工作正常并显示文件。当我键入 ls -als -la 时,出现此错误 -

Get-ChildItem : A parameter cannot be found that matches parameter name 'a'.
At line:1 char:6
+ ls -a <<<<
+ CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterB
indingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
ands.GetChildItemCommand

我的同事在她的同一台计算机上使用这些命令没问题。可能是什么问题?

这是因为您是在 PowerShell 而不是 GitShell 中输入命令。

PowerShell 确实有一个 ls 命令,但它是 Get-ChildItem 的别名,它没有与 unix shell 中的 ls 命令相同的开关。

如果您可以暂时使用 GitHub gui 客户端,请启动它。然后打开 "Options..."(在小齿轮图标下)。然后在 "Default Shell" 的地方选择 "Git Bash" 而不是 "PowerShell".

完成后,您可以打开 Git Shell,它会打开 bash shell,然后您就可以使用 ls -al 和 powershell 不正确的所有其他命令。