git clone 写入 sderr,很好,但为什么我不能重定向到 stdout

git clone writes to sderr, fine but why can't I redirect to stdout

我认为 git clone 使用 STDERR。

我现在想将它重定向到 STDOUT 以使用此 hack

我遇到了一些问题(另外,我使用很棒的 stderred 库来自动将 STDERR 着色为红色)。

您可以在附图中看到问题,对我来说意义不大...请说明为什么会发生这种情况以及如何将所有输出输出到 STDERR,以便我可以正确使用 tee .

与许多 Unix 实用程序一样,git-clone 如果将其重定向到管道,则会更安静。假设输出对人类有用,它只会妨碍程序的运行。 tee 打破了这个假设,但是 git 不知道管道的尽头是什么。

来自 git-clone manual...

--progress

Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.

您必须指定 git clone --progress 以强制其进行完整输出。

这是一个将 stderr 重定向到 stdout 的工作示例。 我最近的用例是修复一个 Github Actions 错误,该错误将所有 stderr 输出放在日志的顶部,而不是将其与 stdout 顺序排列。当 Microsoft 修复此错误时,我将有很多未修复的工作要做...

git 使用 stderr 克隆的证明:

$ (git clone --progress https://github.com/sindresorhus/ora.git 2>&1 | tee true) > cmd.stdout 2> cmd.stderr
$ cat cmd.stderr # Nothing here...
$ cat cmd.stdout
Cloning into 'ora'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 563 (delta 3), reused 7 (delta 2), pack-reused 551
Receiving objects: 100% (563/563), 652.32 KiB | 2.70 MiB/s, done.
Resolving deltas: 100% (346/346), done.

将该 stderr 流踢入 stdout:

$ (git clone --progress https://github.com/sindresorhus/ora.git 2>&1 | tee true) > cmd.stdout 2> cmd.stderr
$ cat cmd.stderr # Nothing here now...
$ cat cmd.stdout
Cloning into 'ora'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 563 (delta 3), reused 7 (delta 2), pack-reused 551
Receiving objects: 100% (563/563), 652.32 KiB | 2.70 MiB/s, done.
Resolving deltas: 100% (346/346), done.