echo .filetoignore >> .gitignore 在 Powershell 中的每个字符之间添加空格



我正试图从Powershell向我的.gitignore文件添加一行。

当我在git bash或命令提示符中运行此命令时:

echo .filetoignore >> .gitignore

它正确地将这一行添加到我的.gitignore文件中:

.filetoignore

当我从Powershell运行相同的命令时,它会在每个字符之间添加一个空格:

. f i l e t o i g n o r e

在Powershell中执行此操作并将此行添加到.gitignore的正确方法是什么?

.filetoignore

这是编码问题。Windows内部总是使用2字节编码的字符串。

避免在powershell中使用>>,使用Add-ContentOut-File -Append[IO.File]::AppendAllLines[IO.File]::AppendText,可以在其中指定使用的编码。

最新更新