为什么“git submodule add ..."写入标准错误而不是标准输出? [英] Why does "git submodule add ..." write to stderr rather than stdout?

查看:43
本文介绍了为什么“git submodule add ..."写入标准错误而不是标准输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

消息

Cloning into 'sub-mod'...
done.

在将 git submodule add... 命令写入 stderr 之后.我希望将消息写入 stdout,因为我认为这并不表示命令出现问题.

after a git submodule add... command is written to stderr. I expected the message to be written to stdout since I don't think it indicates something went wrong with the command.

我可以使用以下命令序列重现这一点:

I can reproduce this with the following sequence of commands:

rm   -rf /tmp/repo /tmp/module
mkdir    /tmp/repo /tmp/module

cd /tmp/module

git init  > /dev/null
echo "foo" > foo;
git add foo > /dev/null
git commit . -m "+ foo" > /dev/null


cd /tmp/repo

git init > /dev/null
git submodule add /tmp/module/ sub-mod 1> /dev/null

如果我将最后一个命令中的重定向更改为 ... 2>/dev/null,什么都不打印.

If I change the redirection in the last command to ... 2> /dev/null, nothing is printed.

推荐答案

这不仅限于子模块,如 在此注明:

This is not limited to submodules, as noted here:

子模块的注册会上报给stderr,就是这样与 Git 中的其余进度报告一致.

The registration of the submodule will be reported to stderr, as that is consistent with the rest of progress reporting within Git.

这有助于我们在以后的补丁中重用init_submodule 函数update_clone 其标准输出将通过管道传输到 shell,它以非常特定的方式从 stdout 读取参数.

This helps us in a later patch when we want to reuse the init_submodule function in update_clone whose stdout will be piped to shell which reads parameters off stdout in a very specific way.

您也可以在 这个最近的补丁:

将 stdout 的输出重新路由到 stderr,因为它只是提供信息消息,不能被机器消费.

Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.

我们想从 submodule update 的助手中初始化子模块在稍后的补丁中,并且消耗了所述助手的 stdout 输出由 submodule update 部分仍然用 shell 编写.

We want to init submodules from the helper for submodule update in a later patch and the stdout output of said helper is consumed by the parts of submodule update which are still written in shell.

所以我们必须小心哪些消息在标准输出上.

So we have to be careful which messages are on stdout.

这篇关于为什么“git submodule add ..."写入标准错误而不是标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆