Git 在 PowerShell 中偏移文本

Git offsets text in PowerShell

我注意到在 PowerShell 中使用 Git 时从未见过的一些非常奇怪的东西。我有一个要向其提交代码的 git 存储库。每当我 运行 git status 查看更改的文件时,我都会看到控制台中的文本在上一行上偏移了一个字符。我也没有re-size了window。这是我所看到的示例:

单词“modified”向前一行偏移了一个字符。

我认为这是 PowerShell 中的一个问题,但在查看了 window 的属性之后,我无法想出任何有效的方法,而且只有在列出时才会出现这种情况修改后的文件(据我所知)。

为什么 Git 在 PowerShell 中像这样偏移文本,我该如何解决?

更新#1
正如@Bassie 在评论中所问,我 运行 git config --list --show-origin [1] 为了列出 git 配置的内容,我得到了以下结果:

配置文件中似乎没有可以执行类似操作的任何选项。

我还注意到,如果我将 PowerShell 置于“传统模式”,那么格式设置会按预期工作。此结果证明这可能是 PowerShell 问题而不是 Git 问题。我的问题仍然存在,如果有人对如何解决这个问题有任何想法,因为这个问题没有出现在我使用 PowerShell 和 Git.

的另一台机器上

更新 #2
因此,在 运行ning git config --list --show-origin 之后,如果我再次 运行 git status,则格式问题会自行解决。但是,如果我 re-open 打开 PowerShell window 而只是 运行 git status,那么格式问题又会出现。这实际上可能是 Git 的一个问题。

@torek 在评论中提供了手头问题的上下文,这让我找到了解决方案:

"Git is printing tab characters, and your window is interpreting "tab" as "move to rightmost column" instead of "move to next mod-8-equals-1 column". [...] It's likely that your pager, whatever it is set to, is sending escape sequences that fix the tab-stop positions in the window. Git itself runs a pager when running certain commands. The chosen pager is from core.pager or $GIT_PAGER or built in, or from command-line flags. git status does not use the pager (for some reason—it probably should, but historically it didn't, and so far, still doesn't) but other Git commands, including git config --list, do."

对此进行了进一步研究后,我发现 the following Whosebug post,它提供了解决方案。解决方案是通过将 Git 配置 pager.status 设置为 true 来为 git status 命令打开寻呼机。这可以通过 运行 执行以下命令来完成:

git config --global pager.status true

完成此操作后,即使 运行 在新的 PowerShell window 中,git status 命令现在也将正常运行,格式问题将消失:

问题已解决! :)