为什么“git submodule add ...”写入stderr而不是stdout? [英] Why does "git submodule add ..." write to stderr rather than stdout?
问题描述
消息
克隆到'sub-mod'...
完成。
在 git submodule add ...之后...
命令被写入 stderr 。我预计这封邮件会被写入 stdout ,因为我不认为这说明命令出了问题。
我可以重现这个使用以下命令序列:
rm -rf / tmp / repo / tmp / module
mkdir / tmp / repo / tmp / module
cd / tmp / module
git init> / dev / null
echofoo> 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
,不会打印任何内容。
这不仅限于子模块, a href =http://git.661346.n2.nabble.com/RFC-PATCH-0-5-WAS-Submodule-Groups-Labels-and-submodule-autoInitialize-tt7646332.html#a7646333 =nofollow >在这里指出:
$ b
子模块的注册将被报告给 stderr,因为它是
与Git中的其他进度报告一致。
这有助于我们在稍后的补丁中重新使用
init_submodule
函数在update_clone
其stdout将会将
引导到shell,以非常特定的方式从stdout中读取参数。
您也可以在这个最新补丁:
$ b
将stdout的输出重新路由到 stderr,因为它只是提供信息的
消息,不会被计算机使用。
我们希望在以后的补丁中从辅助程序中初始化
子模块更新
的子模块,并且所述帮助程序的stdout输出消耗
子模块更新
,它们仍然写在shell中。
所以我们必须小心哪些消息在stdout上。
The message
Cloning into 'sub-mod'...
done.
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
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:
The registration of the submodule will be reported to stderr, as that is consistent with the rest of progress reporting within Git.
This helps us in a later patch when we want to reuse the
init_submodule
function inupdate_clone
whose stdout will be piped to shell which reads parameters off stdout in a very specific way.
You can see it also in this recent patch:
Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.
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 ofsubmodule update
which are still written in shell.So we have to be careful which messages are on stdout.
这篇关于为什么“git submodule add ...”写入stderr而不是stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!