【问题标题】:Output of git command is not fully redirected to a filegit 命令的输出未完全重定向到文件
【发布时间】:2016-10-12 19:12:02
【问题描述】:

git fetch 命令的输出,从下面的 cmd 重定向到“test1”文件:

manish@rigved:~$ git fetch --all --prune > test1
From https://github.com/Beawel/wwwnew
 x [deleted]         (none)     -> origin/test

问题:但是输出中显示的“x [deleted] ...”行没有重定向到test1,为什么?请提出建议。

为什么 git 命令会在 stderr 上打印明显不是的错误消息?

manish@rigved:~$ cat test1
Fetching origin

【问题讨论】:

标签: git redirect


【解决方案1】:

除了stdout,你还需要重定向stderr。

git fetch --all --prune > test1 2>&1

更重要的是,为什么 git 命令会在 stderr 而不是 stdout 上发出信息?
这是 git 特有的(不是有据可查的 stderr 重定向的副本)。

正如我explained here:

它与 Git 中的其他进度报告保持一致。
将 stdout 的输出重新路由到 stderr,因为它只是提供信息的消息,不会被机器使用。

您会在标准输出 git 命令输出中找到可能被链式管道序列中的其他命令使用的命令输出。
任何其他消息(不打算被其他命令使用)都被重定向到 stderr。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多