Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
851 views
in Technique[技术] by (71.8m points)

redirect - Output of git command is not fully redirected to a file

The output of git fetch command, is redirected to "test1" file from the below cmd:

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

Question: However the "x [deleted] ..." line as shown in the output is not redirected to test1, why? Please suggest.

Why a git command would print what is clearly not an error message on stderr?

manish@rigved:~$ cat test1
Fetching origin
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to redirect stderr in addition of stdout.

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

More importantly, why a git command does emit information on stderr instead of stdout?
That is specific to git (and not a duplicate of the well-documented stderr redirection).

As I explained here:

It is consistent with the rest of progress reporting within Git.
Reroute the output of stdout to stderr as it is just informative messages, not to be consumed by machines.

You would find on stdout git command outputs that could potentially by used by other commands in a chained-pipe sequence.
Any other message (not meant to be consumed by other commands) is redirected to stderr.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...